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

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

rusty-gd: make scalar getters return by copy rather than ref

Bug: 171749953
Tag: #gd-refactor
Test: gd/cert/run --rhost SimpleHalTest
Change-Id: I1427e8cc8c252a1eddb68470b1df215cf53c628f
parent 150a8c45
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -128,6 +128,10 @@ class PacketField : public Loggable {

  virtual void GenRustWriter(std::ostream& s, Size start_offset, Size end_offset) const = 0;

  virtual bool GetterIsByRef() const {
    return true;
  }

 private:
  ParseLocation loc_;
  std::string name_;
+4 −0
Original line number Diff line number Diff line
@@ -62,6 +62,10 @@ class ScalarField : public PacketField {

  void GenRustWriter(std::ostream& s, Size start_offset, Size end_offset) const override;

  virtual bool GetterIsByRef() const override {
    return false;
  }

 private:
  const int size_;
};
+9 −3
Original line number Diff line number Diff line
@@ -1021,9 +1021,15 @@ void PacketDef::GenRustAccessStructImpls(std::ostream& s) const {
    });

    for (auto const& field : fields) {
      if (field->GetterIsByRef()) {
        s << "pub fn get_" << field->GetName() << "(&self) -> &" << field->GetRustDataType() << "{";
        s << " &self." << util::CamelCaseToUnderScore(def->name_) << ".as_ref()." << field->GetName();
        s << "}\n";
      } else {
        s << "pub fn get_" << field->GetName() << "(&self) -> " << field->GetRustDataType() << "{";
        s << " self." << util::CamelCaseToUnderScore(def->name_) << ".as_ref()." << field->GetName();
        s << "}\n";
      }
    }
  }

+6 −6
Original line number Diff line number Diff line
@@ -59,7 +59,7 @@ async fn provide_hci(hal_exports: HalExports, rt: Arc<Runtime>) -> HciExports {
    };

    assert!(
        *exports.send(ResetBuilder {}.build()).await.get_status() == ErrorCode::Success,
        exports.send(ResetBuilder {}.build()).await.get_status() == ErrorCode::Success,
        "reset did not complete successfully"
    );

@@ -175,7 +175,7 @@ async fn dispatch(
                match evt.specialize() {
                    CommandStatus(evt) => {
                        hci_timeout.cancel();
                        let this_opcode = *evt.get_command_op_code();
                        let this_opcode = evt.get_command_op_code();
                        match pending_cmd.take() {
                            Some(PendingCommand{opcode, fut}) if opcode == this_opcode  => fut.send(evt.into()).unwrap(),
                            Some(PendingCommand{opcode, ..}) => panic!("Waiting for {:?}, got {:?}", opcode, this_opcode),
@@ -184,7 +184,7 @@ async fn dispatch(
                    },
                    CommandComplete(evt) => {
                        hci_timeout.cancel();
                        let this_opcode = *evt.get_command_op_code();
                        let this_opcode = evt.get_command_op_code();
                        match pending_cmd.take() {
                            Some(PendingCommand{opcode, fut}) if opcode == this_opcode  => fut.send(evt.into()).unwrap(),
                            Some(PendingCommand{opcode, ..}) => panic!("Waiting for {:?}, got {:?}", opcode, this_opcode),
@@ -193,7 +193,7 @@ async fn dispatch(
                    },
                    LeMetaEvent(evt) => {
                        let code = evt.get_subevent_code();
                        match le_evt_handlers.lock().await.get(code) {
                        match le_evt_handlers.lock().await.get(&code) {
                            Some(sender) => sender.send(evt).await.unwrap(),
                            None => panic!("Unhandled le subevent {:?}", code),
                        }
@@ -203,7 +203,7 @@ async fn dispatch(
                    VendorSpecificEvent(_) => {},
                    _ => {
                        let code = evt.get_event_code();
                        match evt_handlers.lock().await.get(code) {
                        match evt_handlers.lock().await.get(&code) {
                            Some(sender) => sender.send(evt).await.unwrap(),
                            None => panic!("Unhandled le subevent {:?}", code),
                        }
@@ -212,7 +212,7 @@ async fn dispatch(
            },
            Some(cmd) = cmd_rx.recv(), if pending_cmd.is_none() => {
                pending_cmd = Some(PendingCommand {
                    opcode: *cmd.cmd.get_op_code(),
                    opcode: cmd.cmd.get_op_code(),
                    fut: cmd.fut,
                });
                cmd_tx.send(cmd.cmd).await.unwrap();