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

Commit 0b98dde2 authored by Zach Johnson's avatar Zach Johnson
Browse files

rusty-gd: add intos for builders, so we can skip the formal build call

Bug: 171749953
Tag: #gd-refactor
Test: gd/cert/run --rhost SimpleHalTest
Change-Id: Ie68b9124b0d6f7b4c52ce882a6966995088d17f6
parent b0533b91
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -1047,6 +1047,17 @@ void PacketDef::GenRustAccessStructImpls(std::ostream& s) const {
}

void PacketDef::GenRustBuilderStructImpls(std::ostream& s) const {
  if (complement_ != nullptr) {
    auto complement_root = complement_->GetRootDef();
    auto complement_root_accessor = util::CamelCaseToUnderScore(complement_root->name_);
    s << "impl CommandExpectations for " << name_ << "Builder {";
    s << " type ResponseType = " << complement_->name_ << "Packet;";
    s << " fn _to_response_type(pkt: EventPacket) -> Self::ResponseType { ";
    s << complement_->name_ << "Packet::new(pkt." << complement_root_accessor << ".clone())";
    s << " }";
    s << "}";
  }

  s << "impl " << name_ << "Builder {";
  s << "pub fn build(self) -> " << name_ << "Packet {";
  auto lineage = GetAncestors();
@@ -1104,6 +1115,13 @@ void PacketDef::GenRustBuilderStructImpls(std::ostream& s) const {
  s << "}\n";

  s << "}\n";
  lineage = GetAncestors();
  for (auto it = lineage.begin(); it != lineage.end(); it++) {
    auto def = *it;
    s << "impl Into<" << def->name_ << "Packet> for " << name_ << "Builder {";
    s << " fn into(self) -> " << def->name_ << "Packet { self.build().into() }";
    s << "}\n";
  }
}

void PacketDef::GenRustDef(std::ostream& s) const {
+1 −1
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@ module! {

macro_rules! assert_success {
    ($hci:ident.send($builder:expr)) => {
        assert!($hci.send($builder.build()).await.get_status() == ErrorCode::Success);
        assert!($hci.send($builder).await.get_status() == ErrorCode::Success);
    };
}

+3 −3
Original line number Diff line number Diff line
//! Host Controller Interface (HCI)

/// HCI controller info
pub mod controller;
/// HCI errors
pub mod error;
/// HCI layer facade service
pub mod facade;
/// HCI controller info
pub mod controller;

use bt_common::time::Alarm;
use bt_hal::HalExports;
@@ -61,7 +61,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 {}).await.get_status() == ErrorCode::Success,
        "reset did not complete successfully"
    );