Skip to content

Commit

Permalink
Merge pull request #63 from embassy-rs/event-handler-closure
Browse files Browse the repository at this point in the history
use a closure for the event handler
  • Loading branch information
lulf authored Jun 17, 2024
2 parents 94f9e82 + 53e1a35 commit cee020a
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions host/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@ impl<const CONNS: usize, const CHANNELS: usize, const L2CAP_MTU: usize, const AD
}
}

/// Event handler for vendor-specific events handled outside the host.
pub trait VendorEventHandler {
fn on_event(&self, event: &Vendor<'_>);
}

/// A BLE Host.
///
/// The BleHost holds the runtime state of the host, and is the entry point
Expand Down Expand Up @@ -890,13 +885,10 @@ where
+ for<'t> ControllerCmdSync<LeSetExtAdvEnable<'t>>
+ ControllerCmdSync<LeReadBufferSize>,
{
self.run_with_handler(None).await
self.run_with_handler(|_| {}).await
}

pub async fn run_with_handler(
&self,
vendor_handler: Option<&dyn VendorEventHandler>,
) -> Result<(), BleHostError<T::Error>>
pub async fn run_with_handler<F: Fn(&Vendor)>(&self, vendor_handler: F) -> Result<(), BleHostError<T::Error>>
where
T: ControllerCmdSync<Disconnect>
+ ControllerCmdSync<SetEventMask>
Expand Down Expand Up @@ -1094,9 +1086,7 @@ where
}
}
Event::Vendor(vendor) => {
if let Some(handler) = vendor_handler {
handler.on_event(&vendor);
}
vendor_handler(&vendor);
}
// Ignore
_ => {}
Expand Down

0 comments on commit cee020a

Please sign in to comment.