use std::marker::PhantomData; pub trait Opaque: Send + Sync + 'static {} impl Opaque for T where T: Send + Sync + '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, 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 {} pub trait TunCallback: Fn(&T, bool, bool) -> () + Sync + Send + 'static {} pub trait BindCallback: Fn(&T, bool, bool) -> () + Sync + Send + 'static {} pub trait Endpoint: Send + Sync {} pub trait Callbacks: Send + Sync + 'static { type Opaque: Opaque; type CallbackRecv: Callback; type CallbackSend: Callback; type CallbackKey: KeyCallback; } pub struct CallbacksPhantom, S: Callback, K: KeyCallback> { _phantom_opaque: PhantomData, _phantom_recv: PhantomData, _phantom_send: PhantomData, _phantom_key: PhantomData } impl , S: Callback, K: KeyCallback> Callbacks for CallbacksPhantom { type Opaque = O; type CallbackRecv = R; type CallbackSend = S; type CallbackKey = K; }