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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
use encoding::EncodingRef;
use encoding::all::UTF_8;
use loirc::{MonitorSettings, ReconnectionSettings};
use ::core::{dispatch, Error};
use ::listener::Listener;
pub struct Settings<'a> {
pub addr: &'a str,
pub nickname: &'a str,
pub username: &'a str,
pub realname: &'a str,
pub reconnection: ReconnectionSettings,
pub monitor: Option<MonitorSettings>,
pub auto_ident: bool,
pub auto_ping: bool,
pub encoding: EncodingRef,
pub password: &'a str,
}
impl<'a> Settings<'a> {
pub fn new<'b>(addr: &'b str, nickname: &'b str) -> Settings<'b> {
Settings {
addr: addr,
nickname: nickname,
username: "hiirc",
realname: "hiirc",
reconnection: ReconnectionSettings::DoNotReconnect,
monitor: None,
auto_ident: true,
auto_ping: true,
encoding: UTF_8,
password: "",
}
}
pub fn username(mut self, username: &'a str) -> Settings<'a> {
self.username = username;
self
}
pub fn realname(mut self, realname: &'a str) -> Settings<'a> {
self.realname = realname;
self
}
pub fn reconnection(mut self, reconnection: ReconnectionSettings) -> Settings<'a> {
self.reconnection = reconnection;
self
}
pub fn monitor(mut self, monitor: Option<MonitorSettings>) -> Settings<'a> {
self.monitor = monitor;
self
}
pub fn auto_ident(mut self, auto_ident: bool) -> Settings<'a> {
self.auto_ident = auto_ident;
self
}
pub fn auto_ping(mut self, auto_ping: bool) -> Settings<'a> {
self.auto_ping = auto_ping;
self
}
pub fn encoding(mut self, encoding: EncodingRef) -> Settings<'a> {
self.encoding = encoding;
self
}
pub fn password(mut self, password: &'a str) -> Settings<'a> {
self.password = password;
self
}
pub fn dispatch<L>(self, listener: L) -> Result<(), Error>
where L: Listener
{
dispatch(listener, self)
}
}