aboutsummaryrefslogtreecommitdiffstats
path: root/src/router/types.rs
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2019-08-31 20:25:16 +0200
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2019-08-31 20:25:16 +0200
commit46d76b80c6b1b3b1c549b770b1a5ba791b49da8a (patch)
tree0c880785943dd00e66cff6d8cd7560d42dc68c24 /src/router/types.rs
parentExplicitly clear t0 in KDF macro (diff)
downloadwireguard-rs-46d76b80c6b1b3b1c549b770b1a5ba791b49da8a.tar.xz
wireguard-rs-46d76b80c6b1b3b1c549b770b1a5ba791b49da8a.zip
Reduce number of type parameters in router
Merge multiple related type parameters into trait, allowing for easier refactoring and better maintainability.
Diffstat (limited to 'src/router/types.rs')
-rw-r--r--src/router/types.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/router/types.rs b/src/router/types.rs
index 3d486bc..f6a0311 100644
--- a/src/router/types.rs
+++ b/src/router/types.rs
@@ -1,3 +1,5 @@
+use std::marker::PhantomData;
+
pub trait Opaque: Send + Sync + 'static {}
impl<T> Opaque for T where T: Send + Sync + 'static {}
@@ -23,3 +25,24 @@ pub trait TunCallback<T>: Fn(&T, bool, bool) -> () + Sync + Send + 'static {}
pub trait BindCallback<T>: Fn(&T, bool, bool) -> () + Sync + Send + 'static {}
pub trait Endpoint: Send + Sync {}
+
+pub trait Callbacks: Send + Sync + 'static {
+ type Opaque: Opaque;
+ type CallbackRecv: Callback<Self::Opaque>;
+ type CallbackSend: Callback<Self::Opaque>;
+ type CallbackKey: KeyCallback<Self::Opaque>;
+}
+
+pub struct CallbacksPhantom<O: Opaque, R: Callback<O>, S: Callback<O>, K: KeyCallback<O>> {
+ _phantom_opaque: PhantomData<O>,
+ _phantom_recv: PhantomData<R>,
+ _phantom_send: PhantomData<S>,
+ _phantom_key: PhantomData<K>
+}
+
+impl <O: Opaque, R: Callback<O>, S: Callback<O>, K: KeyCallback<O>> Callbacks for CallbacksPhantom<O, R, S, K> {
+ type Opaque = O;
+ type CallbackRecv = R;
+ type CallbackSend = S;
+ type CallbackKey = K;
+} \ No newline at end of file