diff options
author | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2019-08-27 11:28:20 +0200 |
---|---|---|
committer | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2019-08-27 11:28:20 +0200 |
commit | a80e64014c21e092e35080baf29b2611d18c486a (patch) | |
tree | 6d9c044a54aa5a8c48a121397a1c4a89b37be1dc /src/router/types.rs | |
parent | Work on callback structure for cryptkey router (diff) | |
download | wireguard-rs-a80e64014c21e092e35080baf29b2611d18c486a.tar.xz wireguard-rs-a80e64014c21e092e35080baf29b2611d18c486a.zip |
Unbox callback closures
Accepted the more verbose type signatures and added a callback to
request new key-material.
Diffstat (limited to 'src/router/types.rs')
-rw-r--r-- | src/router/types.rs | 16 |
1 files changed, 14 insertions, 2 deletions
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<T> Opaque for T where T: Send + Sync + 'static {} -pub trait Callback<T>: 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<T>: Fn(&T, bool, bool) -> () + Sync + Send + 'static {} -impl<T, F> Callback<T> for F where F: Fn(&T, bool) -> () + Sync + Send + 'static {} +impl<T, F> Callback<T> 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<T>: Fn(&T) -> () + Sync + Send + 'static {} + +impl<T, F> KeyCallback<T> for F where F: Fn(&T) -> () + Sync + Send + 'static {}
\ No newline at end of file |