From a80e64014c21e092e35080baf29b2611d18c486a Mon Sep 17 00:00:00 2001 From: Mathias Hall-Andersen Date: Tue, 27 Aug 2019 11:28:20 +0200 Subject: Unbox callback closures Accepted the more verbose type signatures and added a callback to request new key-material. --- src/router/types.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/router/types.rs') diff --git a/src/router/types.rs b/src/router/types.rs index 0b5e162..2ed011b 100644 --- a/src/router/types.rs +++ b/src/router/types.rs @@ -2,6 +2,18 @@ pub trait Opaque: Send + Sync + 'static {} impl Opaque for T where T: Send + Sync + 'static {} -pub trait Callback: Fn(&T, bool) -> () + Sync + Send + 'static {} +/// A send/recv callback takes 3 arguments: +/// +/// * `0`, a reference to the opaque value assigned to the peer +/// * `1`, a bool indicating whether the message contained data (not just keepalive) +/// * `2`, a bool indicating whether the message was transmitted (i.e. did the peer have an associated endpoint?) +pub trait Callback: Fn(&T, bool, bool) -> () + Sync + Send + 'static {} -impl Callback for F where F: Fn(&T, bool) -> () + Sync + Send + 'static {} +impl Callback for F where F: Fn(&T, bool, bool) -> () + Sync + Send + 'static {} + +/// A key callback takes 1 argument +/// +/// * `0`, a reference to the opaque value assigned to the peer +pub trait KeyCallback: Fn(&T) -> () + Sync + Send + 'static {} + +impl KeyCallback for F where F: Fn(&T) -> () + Sync + Send + 'static {} \ No newline at end of file -- cgit v1.2.3-59-g8ed1b