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
use crate::Settings;
pub trait IntoSettings {
fn apply_to_settings(self, settings: &mut Settings) -> std::io::Result<()>;
}
impl<F> IntoSettings for F
where
F: FnOnce(Settings) -> std::io::Result<Settings>,
{
fn apply_to_settings(self, settings: &mut Settings) -> std::io::Result<()> {
*settings = (self)(settings.clone())?;
Ok(())
}
}
impl IntoSettings for u32 {
fn apply_to_settings(self, settings: &mut Settings) -> std::io::Result<()> {
settings.set_baud_rate(self)?;
settings.set_char_size(crate::CharSize::Bits8);
settings.set_stop_bits(crate::StopBits::One);
settings.set_parity(crate::Parity::None);
settings.set_flow_control(crate::FlowControl::None);
Ok(())
}
}
pub struct KeepSettings;
impl IntoSettings for KeepSettings {
fn apply_to_settings(self, _settings: &mut Settings) -> std::io::Result<()> {
Ok(())
}
}