Skip to content

Commit 6176f36

Browse files
committed
gcoap: add helper
1 parent 87f33b8 commit 6176f36

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/gcoap.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,20 @@ pub trait Handler {
9595
fn handle(&mut self, pkt: &mut PacketBuffer) -> isize;
9696
}
9797

98+
/// A wrapper that implements gnrc::Handler for closures. This allows easy compact writing of
99+
/// ad-hoc handlers.
100+
pub struct ClosureHandler<H>(pub H) where
101+
H: FnMut(&mut PacketBuffer) -> isize
102+
;
103+
impl<H> Handler for ClosureHandler<H> where
104+
H: FnMut(&mut PacketBuffer) -> isize
105+
{
106+
fn handle(&mut self, pkt: &mut PacketBuffer) -> isize {
107+
self.0(pkt)
108+
}
109+
}
110+
111+
98112
// Questionable code starts here
99113

100114
use riot_sys::libc::{c_uint};

0 commit comments

Comments
 (0)