use std::io::Error; use fehler::throws; use super::TunInterface; #[derive(Debug, Clone, Default)] #[cfg_attr( feature = "serde", derive(serde::Serialize, serde::Deserialize, schemars::JsonSchema) )] pub struct TunOptions { /// (Windows + Linux) Name the tun interface. pub name: Option, /// (Linux) Don't include packet information. pub no_pi: bool, /// (Linux) Avoid opening an existing persistant device. pub tun_excl: bool, /// (Linux) The IP address of the tun interface. pub address: Option, } impl TunOptions { pub fn new() -> Self { Self::default() } pub fn name(mut self, name: &str) -> Self { self.name = Some(name.to_owned()); self } pub fn no_pi(mut self, enable: bool) -> Self { self.no_pi = enable; self } pub fn tun_excl(mut self, enable: bool) -> Self { self.tun_excl = enable; self } pub fn address(mut self, address: impl ToString) -> Self { self.address = Some(address.to_string()); self } #[throws] pub fn open(self) -> TunInterface { TunInterface::new_with_options(self)? } }