Skip to content

Commit 72f636f

Browse files
committed
fix: allow returning type from metrics
1 parent 7093098 commit 72f636f

File tree

6 files changed

+16
-16
lines changed

6 files changed

+16
-16
lines changed

host/src/channel_manager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,10 +758,10 @@ impl<'d> ChannelManager<'d> {
758758
}
759759

760760
#[cfg(feature = "channel-metrics")]
761-
pub(crate) fn metrics<F: FnOnce(&Metrics)>(&self, index: ChannelIndex, f: F) {
761+
pub(crate) fn metrics<F: FnOnce(&Metrics) -> R, R>(&self, index: ChannelIndex, f: F) -> R {
762762
self.with_mut(|state| {
763763
let state = &state.channels[index.0 as usize];
764-
f(&state.metrics);
764+
f(&state.metrics)
765765
})
766766
}
767767
}

host/src/connection.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,8 @@ impl<'stack> Connection<'stack> {
334334

335335
/// Read metrics for this connection
336336
#[cfg(feature = "connection-metrics")]
337-
pub fn metrics<F: FnOnce(&ConnectionMetrics)>(&self, f: F) {
338-
self.manager.metrics(self.index, f);
337+
pub fn metrics<F: FnOnce(&ConnectionMetrics) -> R, R>(&self, f: F) -> R {
338+
self.manager.metrics(self.index, f)
339339
}
340340

341341
/// The RSSI value for this connection.

host/src/connection_manager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,10 +711,10 @@ impl<'d> ConnectionManager<'d> {
711711
}
712712

713713
#[cfg(feature = "connection-metrics")]
714-
pub(crate) fn metrics<F: FnOnce(&Metrics)>(&self, index: u8, f: F) {
714+
pub(crate) fn metrics<F: FnOnce(&Metrics) -> R, R>(&self, index: u8, f: F) -> R {
715715
self.with_mut(|state| {
716716
let state = &state.connections[index as usize];
717-
f(&state.metrics);
717+
f(&state.metrics)
718718
})
719719
}
720720
}

host/src/host.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,9 +519,9 @@ where
519519
}
520520

521521
/// Read current host metrics
522-
pub(crate) fn metrics<F: FnOnce(&HostMetrics)>(&self, f: F) {
522+
pub(crate) fn metrics<F: FnOnce(&HostMetrics) -> R, R>(&self, f: F) -> R {
523523
let m = self.metrics.borrow();
524-
f(&m);
524+
f(&m)
525525
}
526526

527527
/// Log status information of the host

host/src/l2cap.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ impl<'d> L2capChannel<'d> {
150150

151151
/// Read metrics of the l2cap channel.
152152
#[cfg(feature = "channel-metrics")]
153-
pub fn metrics<F: FnOnce(&ChannelMetrics)>(&self, f: F) {
154-
self.manager.metrics(self.index, f);
153+
pub fn metrics<F: FnOnce(&ChannelMetrics) -> R, R>(&self, f: F) -> R {
154+
self.manager.metrics(self.index, f)
155155
}
156156

157157
/// Await an incoming connection request matching the list of PSM.
@@ -250,8 +250,8 @@ impl<'d> L2capChannelReader<'d> {
250250

251251
/// Read metrics of the l2cap channel.
252252
#[cfg(feature = "channel-metrics")]
253-
pub fn metrics<F: FnOnce(&ChannelMetrics)>(&self, f: F) {
254-
self.manager.metrics(self.index, f);
253+
pub fn metrics<F: FnOnce(&ChannelMetrics) -> R, R>(&self, f: F) -> R {
254+
self.manager.metrics(self.index, f)
255255
}
256256
}
257257

@@ -300,7 +300,7 @@ impl<'d> L2capChannelWriter<'d> {
300300

301301
/// Read metrics of the l2cap channel.
302302
#[cfg(feature = "channel-metrics")]
303-
pub fn metrics<F: FnOnce(&ChannelMetrics)>(&self, f: F) {
304-
self.manager.metrics(self.index, f);
303+
pub fn metrics<F: FnOnce(&ChannelMetrics) -> R, R>(&self, f: F) -> R {
304+
self.manager.metrics(self.index, f)
305305
}
306306
}

host/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,8 @@ impl<'stack, C: Controller> Stack<'stack, C> {
556556
}
557557

558558
/// Read current host metrics
559-
pub fn metrics<F: FnOnce(&HostMetrics)>(&self, f: F) {
560-
self.host.metrics(f);
559+
pub fn metrics<F: FnOnce(&HostMetrics) -> R, R>(&self, f: F) -> R {
560+
self.host.metrics(f)
561561
}
562562

563563
/// Log status information of the host

0 commit comments

Comments
 (0)