diff options
author | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2019-08-31 20:25:16 +0200 |
---|---|---|
committer | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2019-08-31 20:25:16 +0200 |
commit | 46d76b80c6b1b3b1c549b770b1a5ba791b49da8a (patch) | |
tree | 0c880785943dd00e66cff6d8cd7560d42dc68c24 /src/main.rs | |
parent | Explicitly clear t0 in KDF macro (diff) | |
download | wireguard-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 '')
-rw-r--r-- | src/main.rs | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs index 600e144..cfe93eb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,7 +13,44 @@ use std::net::SocketAddr; use std::sync::Arc; use std::time::Duration; -use types::{Bind, KeyPair}; +use types::{Bind, KeyPair, Tun}; + +#[derive(Debug)] +enum TunError {} + +impl Error for TunError { + fn description(&self) -> &str { + "Generic Tun Error" + } + + fn source(&self) -> Option<&(dyn Error + 'static)> { + None + } +} + +impl fmt::Display for TunError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "Not Possible") + } +} + +struct TunTest {} + +impl Tun for TunTest { + type Error = TunError; + + fn mtu(&self) -> usize { + 1500 + } + + fn read(&self, buf: &mut [u8], offset: usize) -> Result<usize, Self::Error> { + Ok(0) + } + + fn write(&self, src: &[u8]) -> Result<(), Self::Error> { + Ok(()) + } +} struct Test {} @@ -73,6 +110,7 @@ fn main() { { let router = router::Device::new( 4, + TunTest {}, |t: &PeerTimer, data: bool, sent: bool| t.a.reset(Duration::from_millis(1000)), |t: &PeerTimer, data: bool, sent: bool| t.b.reset(Duration::from_millis(1000)), |t: &PeerTimer| println!("new key requested"), |