1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use core::num::NonZeroU32;
use std::net::SocketAddr;
#[derive(Debug, Clone, Default)]
pub struct Config {
is_ipv6: bool,
pub bind: Option<SocketAddr>,
pub interface_index: Option<NonZeroU32>,
pub ttl: Option<u32>,
pub fib: Option<u32>,
}
impl Config {
pub fn new() -> Self {
Self::default()
}
pub fn with_ipv6() -> Self {
Self {
is_ipv6: true,
..Default::default()
}
}
pub fn is_ipv6(&self) -> bool {
self.bind.map(|x| x.is_ipv6()).unwrap_or(self.is_ipv6)
}
}
impl Config {
pub fn bind(mut self, bind: SocketAddr) -> Self {
self.bind = Some(bind);
self
}
pub fn interface_index(mut self, interface_index: NonZeroU32) -> Self {
self.interface_index = Some(interface_index);
self
}
pub fn ttl(mut self, ttl: u32) -> Self {
self.ttl = Some(ttl);
self
}
pub fn fib(mut self, fib: u32) -> Self {
self.fib = Some(fib);
self
}
}