Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bce97313 authored by Zach Johnson's avatar Zach Johnson
Browse files

rusty-gd: Add child & into for pub access packet structs

Bug: 171749953
Tag: #gd-refactor
Test: gd/cert/run --rhost SimpleHalTest
Change-Id: Ib4a0516495246ab73b981f8259500f4ab2a98d17
parent 17cb6146
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -916,8 +916,28 @@ void PacketDef::GenRustStructImpls(std::ostream& s) const {
  s << "}\n";
}

void PacketDef::GenRustAccessStructImpls(std::ostream& s) const {
  s << "impl " << name_ << "Packet {";
  if (!children_.empty()) {
    s << " fn specialize(self) -> " << name_ << "Child { unimplemented!(); }";
  }
  s << " fn new(root: Rc<" << GetRootDef()->name_ << "Data>) -> Self { unimplemented!(); }";
  s << "}\n";

  auto parent = parent_;
  while (parent != nullptr) {
    s << "impl Into<" << parent->name_ << "Packet> for " << name_ << "Packet {";
    s << " fn into(self) -> " << parent->name_ << "Packet {";
    s << parent->name_ << "Packet::new(self.root)";
    s << " }";
    s << "}\n";
    parent = parent->parent_;
  }
}

void PacketDef::GenRustDef(std::ostream& s) const {
  GenRustChildEnums(s);
  GenRustStructDeclarations(s);
  GenRustStructImpls(s);
  GenRustAccessStructImpls(s);
}
+2 −0
Original line number Diff line number Diff line
@@ -77,5 +77,7 @@ class PacketDef : public ParentDef {

  void GenRustStructImpls(std::ostream& s) const;

  void GenRustAccessStructImpls(std::ostream& s) const;

  void GenRustDef(std::ostream& s) const;
};