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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use super::*;

#[derive(Debug, Clone, Eq, PartialEq)]
pub enum BindOptions {
    Listen(Valid<ListenerOptions>),
    Call(Valid<CallerOptions>),
    Rendezvous(Valid<RendezvousOptions>),
}

impl From<Valid<ListenerOptions>> for BindOptions {
    fn from(options: Valid<ListenerOptions>) -> Self {
        BindOptions::Listen(options)
    }
}

impl From<Valid<CallerOptions>> for BindOptions {
    fn from(options: Valid<CallerOptions>) -> Self {
        BindOptions::Call(options)
    }
}

impl From<Valid<RendezvousOptions>> for BindOptions {
    fn from(options: Valid<RendezvousOptions>) -> Self {
        BindOptions::Rendezvous(options)
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn into() {
        let caller = CallerOptions::new("127.0.0.1:42", Some("stream ID"))
            .unwrap()
            .with(Connect::default())
            .unwrap()
            .with(Session::default())
            .unwrap()
            .with(Encryption::default())
            .unwrap()
            .with(Sender::default())
            .unwrap()
            .with(Receiver::default())
            .unwrap();

        let listener = ListenerOptions::new(":42")
            .unwrap()
            .with(Connect::default())
            .unwrap()
            .with(Session::default())
            .unwrap()
            .with3(
                Encryption::default(),
                Sender::default(),
                Receiver::default(),
            )
            .unwrap();

        let rendezvous = RendezvousOptions::new("127.0.0.1:42")
            .unwrap()
            .with(Connect::default())
            .unwrap()
            .with(Session::default())
            .unwrap()
            .with(Encryption::default())
            .unwrap()
            .with2(Sender::default(), Receiver::default())
            .unwrap();

        let _: BindOptions = caller.into();
        let _: BindOptions = listener.into();
        let _: BindOptions = rendezvous.into();
    }
}