Debian Codegraph @

src/mode.rs

raw symbols SCIP
1 //! A module defining an API for IRC user and channel modes.
2 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/;
3
4 use craterust-analyzer cargo irc-proto 1.1.0 crate/::commandrust-analyzer cargo irc-proto 1.1.0 command/::Commandrust-analyzer cargo irc-proto 1.1.0 command/Command#;
5 use craterust-analyzer cargo irc-proto 1.1.0 crate/::errorrust-analyzer cargo irc-proto 1.1.0 error/::MessageParseErrorrust-analyzer cargo irc-proto 1.1.0 error/MessageParseError#;
6
7 /// A marker trait for different kinds of Modes.
8 pub trait ModeTyperust-analyzer cargo irc-proto 1.1.0 mode/ModeType#: fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# + fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# + PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq# {
9 /// Creates a command of this kind.
10 fn moderust-analyzer cargo irc-proto 1.1.0 mode/ModeType#mode().(target: &str, modes: &[Moderust-analyzer cargo irc-proto 1.1.0 mode/Mode#<Self>]) -> Commandrust-analyzer cargo irc-proto 1.1.0 command/Command#;
11
12 /// Returns true if this mode takes an argument, and false otherwise.
13 fn takes_argrust-analyzer cargo irc-proto 1.1.0 mode/ModeType#takes_arg().(&self) -> bool;
14
15 /// Creates a Mode from a given char.
16 fn from_charrust-analyzer cargo irc-proto 1.1.0 mode/ModeType#from_char().(c: char) -> Self;
17 }
18
19 /// User modes for the MODE command.
20 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
21 pub enum UserModerust-analyzer cargo irc-proto 1.1.0 mode/UserMode# {
22 /// a - user is flagged as away
23 Awayrust-analyzer cargo irc-proto 1.1.0 mode/UserMode#Away#,
24 /// i - marks a users as invisible
25 Invisiblerust-analyzer cargo irc-proto 1.1.0 mode/UserMode#Invisible#,
26 /// w - user receives wallops
27 Wallopsrust-analyzer cargo irc-proto 1.1.0 mode/UserMode#Wallops#,
28 /// r - restricted user connection
29 Restrictedrust-analyzer cargo irc-proto 1.1.0 mode/UserMode#Restricted#,
30 /// o - operator flag
31 Operrust-analyzer cargo irc-proto 1.1.0 mode/UserMode#Oper#,
32 /// O - local operator flag
33 LocalOperrust-analyzer cargo irc-proto 1.1.0 mode/UserMode#LocalOper#,
34 /// s - marks a user for receipt of server notices
35 ServerNoticesrust-analyzer cargo irc-proto 1.1.0 mode/UserMode#ServerNotices#,
36 /// x - masked hostname
37 MaskedHostrust-analyzer cargo irc-proto 1.1.0 mode/UserMode#MaskedHost#,
38
39 /// Any other unknown-to-the-crate mode.
40 Unknownrust-analyzer cargo irc-proto 1.1.0 mode/UserMode#Unknown#(char),
41 }
42
43 impl ModeTyperust-analyzer cargo irc-proto 1.1.0 mode/ModeType# for UserModerust-analyzer cargo irc-proto 1.1.0 mode/UserMode# {
44 fn moderust-analyzer cargo irc-proto 1.1.0 mode/impl#[UserMode][ModeType]mode().(target: &str, modes: &[Moderust-analyzer cargo irc-proto 1.1.0 mode/Mode#<Selfrust-analyzer cargo irc-proto 1.1.0 mode/impl#[UserMode][ModeType]>]) -> Commandrust-analyzer cargo irc-proto 1.1.0 command/Command# {
45 Commandrust-analyzer cargo irc-proto 1.1.0 command/Command#::UserMODErust-analyzer cargo irc-proto 1.1.0 command/Command#UserMODE#(target.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), modes.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`][ToOwned]to_owned().())
46 }
47
48 fn takes_argrust-analyzer cargo irc-proto 1.1.0 mode/impl#[UserMode][ModeType]takes_arg().(&self) -> bool {
49 false
50 }
51
52 fn from_charrust-analyzer cargo irc-proto 1.1.0 mode/impl#[UserMode][ModeType]from_char().(c: char) -> UserModerust-analyzer cargo irc-proto 1.1.0 mode/UserMode# {
53 use selfrust-analyzer cargo irc-proto 1.1.0 mode/::UserModerust-analyzer cargo irc-proto 1.1.0 mode/UserMode#::*;
54
55 match c {
56 'a' => Awayrust-analyzer cargo irc-proto 1.1.0 mode/UserMode#Away#,
57 'i' => Invisiblerust-analyzer cargo irc-proto 1.1.0 mode/UserMode#Invisible#,
58 'w' => Wallopsrust-analyzer cargo irc-proto 1.1.0 mode/UserMode#Wallops#,
59 'r' => Restrictedrust-analyzer cargo irc-proto 1.1.0 mode/UserMode#Restricted#,
60 'o' => Operrust-analyzer cargo irc-proto 1.1.0 mode/UserMode#Oper#,
61 'O' => LocalOperrust-analyzer cargo irc-proto 1.1.0 mode/UserMode#LocalOper#,
62 's' => ServerNoticesrust-analyzer cargo irc-proto 1.1.0 mode/UserMode#ServerNotices#,
63 'x' => MaskedHostrust-analyzer cargo irc-proto 1.1.0 mode/UserMode#MaskedHost#,
64 _ => Unknownrust-analyzer cargo irc-proto 1.1.0 mode/UserMode#Unknown#(c),
65 }
66 }
67 }
68
69 impl fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for UserModerust-analyzer cargo irc-proto 1.1.0 mode/UserMode# {
70 fn fmtrust-analyzer cargo irc-proto 1.1.0 mode/impl#[UserMode][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
71 use selfrust-analyzer cargo irc-proto 1.1.0 mode/::UserModerust-analyzer cargo irc-proto 1.1.0 mode/UserMode#::*;
72
73 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(
74 f,
75 "{}",
76 match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self {
77 Awayrust-analyzer cargo irc-proto 1.1.0 mode/UserMode#Away# => 'a',
78 Invisiblerust-analyzer cargo irc-proto 1.1.0 mode/UserMode#Invisible# => 'i',
79 Wallopsrust-analyzer cargo irc-proto 1.1.0 mode/UserMode#Wallops# => 'w',
80 Restrictedrust-analyzer cargo irc-proto 1.1.0 mode/UserMode#Restricted# => 'r',
81 Operrust-analyzer cargo irc-proto 1.1.0 mode/UserMode#Oper# => 'o',
82 LocalOperrust-analyzer cargo irc-proto 1.1.0 mode/UserMode#LocalOper# => 'O',
83 ServerNoticesrust-analyzer cargo irc-proto 1.1.0 mode/UserMode#ServerNotices# => 's',
84 MaskedHostrust-analyzer cargo irc-proto 1.1.0 mode/UserMode#MaskedHost# => 'x',
85 Unknownrust-analyzer cargo irc-proto 1.1.0 mode/UserMode#Unknown#(c) => c,
86 }
87 )
88 }
89 }
90
91 /// Channel modes for the MODE command.
92 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
93 pub enum ChannelModerust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode# {
94 /// b - ban the user from joining or speaking in the channel
95 Banrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Ban#,
96 /// e - exemptions from bans
97 Exceptionrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Exception#,
98 /// l - limit the maximum number of users in a channel
99 Limitrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Limit#,
100 /// i - channel becomes invite-only
101 InviteOnlyrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#InviteOnly#,
102 /// I - exception to invite-only rule
103 InviteExceptionrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#InviteException#,
104 /// k - specify channel key
105 Keyrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Key#,
106 /// m - channel is in moderated mode
107 Moderatedrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Moderated#,
108 /// r - entry for registered users only
109 RegisteredOnlyrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#RegisteredOnly#,
110 /// s - channel is hidden from listings
111 Secretrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Secret#,
112 /// t - require permissions to edit topic
113 ProtectedTopicrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#ProtectedTopic#,
114 /// n - users must join channels to message them
115 NoExternalMessagesrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#NoExternalMessages#,
116
117 /// q - user gets founder permission
118 Founderrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Founder#,
119 /// a - user gets admin or protected permission
120 Adminrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Admin#,
121 /// o - user gets oper permission
122 Operrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Oper#,
123 /// h - user gets halfop permission
124 Halfoprust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Halfop#,
125 /// v - user gets voice permission
126 Voicerust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Voice#,
127
128 /// Any other unknown-to-the-crate mode.
129 Unknownrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Unknown#(char),
130 }
131
132 impl ModeTyperust-analyzer cargo irc-proto 1.1.0 mode/ModeType# for ChannelModerust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode# {
133 fn moderust-analyzer cargo irc-proto 1.1.0 mode/impl#[ChannelMode][ModeType]mode().(target: &str, modes: &[Moderust-analyzer cargo irc-proto 1.1.0 mode/Mode#<Selfrust-analyzer cargo irc-proto 1.1.0 mode/impl#[ChannelMode][ModeType]>]) -> Commandrust-analyzer cargo irc-proto 1.1.0 command/Command# {
134 Commandrust-analyzer cargo irc-proto 1.1.0 command/Command#::ChannelMODErust-analyzer cargo irc-proto 1.1.0 command/Command#ChannelMODE#(target.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), modes.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`][ToOwned]to_owned().())
135 }
136
137 fn takes_argrust-analyzer cargo irc-proto 1.1.0 mode/impl#[ChannelMode][ModeType]takes_arg().(&self) -> bool {
138 use selfrust-analyzer cargo irc-proto 1.1.0 mode/::ChannelModerust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#::*;
139
140 matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(
141 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self,
142 Banrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Ban# | Exceptionrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Exception#
143 | Limitrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Limit#
144 | InviteExceptionrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#InviteException#
145 | Keyrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Key#
146 | Founderrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Founder#
147 | Adminrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Admin#
148 | Operrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Oper#
149 | Halfoprust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Halfop#
150 | Voicerust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Voice#
151 )
152 }
153
154 fn from_charrust-analyzer cargo irc-proto 1.1.0 mode/impl#[ChannelMode][ModeType]from_char().(c: char) -> ChannelModerust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode# {
155 use selfrust-analyzer cargo irc-proto 1.1.0 mode/::ChannelModerust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#::*;
156
157 match c {
158 'b' => Banrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Ban#,
159 'e' => Exceptionrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Exception#,
160 'l' => Limitrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Limit#,
161 'i' => InviteOnlyrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#InviteOnly#,
162 'I' => InviteExceptionrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#InviteException#,
163 'k' => Keyrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Key#,
164 'm' => Moderatedrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Moderated#,
165 'r' => RegisteredOnlyrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#RegisteredOnly#,
166 's' => Secretrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Secret#,
167 't' => ProtectedTopicrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#ProtectedTopic#,
168 'n' => NoExternalMessagesrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#NoExternalMessages#,
169 'q' => Founderrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Founder#,
170 'a' => Adminrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Admin#,
171 'o' => Operrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Oper#,
172 'h' => Halfoprust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Halfop#,
173 'v' => Voicerust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Voice#,
174 _ => Unknownrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Unknown#(c),
175 }
176 }
177 }
178
179 impl fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for ChannelModerust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode# {
180 fn fmtrust-analyzer cargo irc-proto 1.1.0 mode/impl#[ChannelMode][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
181 use selfrust-analyzer cargo irc-proto 1.1.0 mode/::ChannelModerust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#::*;
182
183 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(
184 f,
185 "{}",
186 match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self {
187 Banrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Ban# => 'b',
188 Exceptionrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Exception# => 'e',
189 Limitrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Limit# => 'l',
190 InviteOnlyrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#InviteOnly# => 'i',
191 InviteExceptionrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#InviteException# => 'I',
192 Keyrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Key# => 'k',
193 Moderatedrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Moderated# => 'm',
194 RegisteredOnlyrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#RegisteredOnly# => 'r',
195 Secretrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Secret# => 's',
196 ProtectedTopicrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#ProtectedTopic# => 't',
197 NoExternalMessagesrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#NoExternalMessages# => 'n',
198 Founderrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Founder# => 'q',
199 Adminrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Admin# => 'a',
200 Operrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Oper# => 'o',
201 Halfoprust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Halfop# => 'h',
202 Voicerust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Voice# => 'v',
203 Unknownrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Unknown#(c) => c,
204 }
205 )
206 }
207 }
208
209 /// A mode argument for the MODE command.
210 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
211 pub enum Moderust-analyzer cargo irc-proto 1.1.0 mode/Mode#<T>
212 where
213 T: ModeTyperust-analyzer cargo irc-proto 1.1.0 mode/ModeType#,
214 {
215 /// Adding the specified mode, optionally with an argument.
216 Plusrust-analyzer cargo irc-proto 1.1.0 mode/Mode#Plus#(T, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>),
217 /// Removing the specified mode, optionally with an argument.
218 Minusrust-analyzer cargo irc-proto 1.1.0 mode/Mode#Minus#(T, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>),
219 /// No prefix mode, used to query ban list on channel join.
220 NoPrefixrust-analyzer cargo irc-proto 1.1.0 mode/Mode#NoPrefix#(T),
221 }
222
223 impl<T> Moderust-analyzer cargo irc-proto 1.1.0 mode/Mode#<T>
224 where
225 T: ModeTyperust-analyzer cargo irc-proto 1.1.0 mode/ModeType#,
226 {
227 /// Creates a plus mode with an `&str` argument.
228 pub fn plusrust-analyzer cargo irc-proto 1.1.0 mode/impl#[`Mode<T>`]plus().(inner: T, arg: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str>) -> Moderust-analyzer cargo irc-proto 1.1.0 mode/Mode#<T> {
229 Moderust-analyzer cargo irc-proto 1.1.0 mode/Mode#::Plusrust-analyzer cargo irc-proto 1.1.0 mode/Mode#Plus#(inner, arg.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|s| s.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()))
230 }
231
232 /// Creates a minus mode with an `&str` argument.
233 pub fn minusrust-analyzer cargo irc-proto 1.1.0 mode/impl#[`Mode<T>`]minus().(inner: T, arg: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str>) -> Moderust-analyzer cargo irc-proto 1.1.0 mode/Mode#<T> {
234 Moderust-analyzer cargo irc-proto 1.1.0 mode/Mode#::Minusrust-analyzer cargo irc-proto 1.1.0 mode/Mode#Minus#(inner, arg.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|s| s.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()))
235 }
236
237 /// Create a no prefix mode with an `&str` argument.
238 pub fn no_prefixrust-analyzer cargo irc-proto 1.1.0 mode/impl#[`Mode<T>`]no_prefix().(inner: T) -> Moderust-analyzer cargo irc-proto 1.1.0 mode/Mode#<T> {
239 Moderust-analyzer cargo irc-proto 1.1.0 mode/Mode#::NoPrefixrust-analyzer cargo irc-proto 1.1.0 mode/Mode#NoPrefix#(inner)
240 }
241
242 /// Gets the mode flag associated with this mode with a + or - prefix as needed.
243 pub fn flagrust-analyzer cargo irc-proto 1.1.0 mode/impl#[`Mode<T>`]flag().(&self) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
244 match self {
245 Moderust-analyzer cargo irc-proto 1.1.0 mode/Mode#::Plusrust-analyzer cargo irc-proto 1.1.0 mode/Mode#Plus#(mode, _) => formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("+{}", mode),
246 Moderust-analyzer cargo irc-proto 1.1.0 mode/Mode#::Minusrust-analyzer cargo irc-proto 1.1.0 mode/Mode#Minus#(mode, _) => formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("-{}", mode),
247 Moderust-analyzer cargo irc-proto 1.1.0 mode/Mode#::NoPrefixrust-analyzer cargo irc-proto 1.1.0 mode/Mode#NoPrefix#(mode) => mode.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
248 }
249 }
250
251 /// Gets the arg associated with this mode, if any. Only some channel modes support arguments,
252 /// e.g. b (ban) or o (oper).
253 pub fn argrust-analyzer cargo irc-proto 1.1.0 mode/impl#[`Mode<T>`]arg().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str> {
254 match self {
255 Moderust-analyzer cargo irc-proto 1.1.0 mode/Mode#::Plusrust-analyzer cargo irc-proto 1.1.0 mode/Mode#Plus#(_, arg) | Moderust-analyzer cargo irc-proto 1.1.0 mode/Mode#::Minusrust-analyzer cargo irc-proto 1.1.0 mode/Mode#Minus#(_, arg) => arg.as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().(),
256 _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
257 }
258 }
259 }
260
261 impl<T> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for Moderust-analyzer cargo irc-proto 1.1.0 mode/Mode#<T>
262 where
263 T: ModeTyperust-analyzer cargo irc-proto 1.1.0 mode/ModeType#,
264 {
265 fn fmtrust-analyzer cargo irc-proto 1.1.0 mode/impl#[`Mode<T>`][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
266 match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self {
267 Moderust-analyzer cargo irc-proto 1.1.0 mode/Mode#::Plusrust-analyzer cargo irc-proto 1.1.0 mode/Mode#Plus#(_, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref arg)) | Moderust-analyzer cargo irc-proto 1.1.0 mode/Mode#::Minusrust-analyzer cargo irc-proto 1.1.0 mode/Mode#Minus#(_, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref arg)) => {
268 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{} {}", self.flagrust-analyzer cargo irc-proto 1.1.0 mode/impl#[`Mode<T>`]flag().(), arg)
269 }
270 _ => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{}", self.flagrust-analyzer cargo irc-proto 1.1.0 mode/impl#[`Mode<T>`]flag().()),
271 }
272 }
273 }
274
275 enum PlusMinusrust-analyzer cargo irc-proto 1.1.0 mode/PlusMinus# {
276 Plusrust-analyzer cargo irc-proto 1.1.0 mode/PlusMinus#Plus#,
277 Minusrust-analyzer cargo irc-proto 1.1.0 mode/PlusMinus#Minus#,
278 NoPrefixrust-analyzer cargo irc-proto 1.1.0 mode/PlusMinus#NoPrefix#,
279 }
280
281 // MODE user [modes]
282 impl Moderust-analyzer cargo irc-proto 1.1.0 mode/Mode#<UserModerust-analyzer cargo irc-proto 1.1.0 mode/UserMode#> {
283 // TODO: turning more edge cases into errors.
284 /// Parses the specified mode string as user modes.
285 pub fn as_user_modesrust-analyzer cargo irc-proto 1.1.0 mode/impl#[`Mode<UserMode>`]as_user_modes().(pieces: &[&str]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Moderust-analyzer cargo irc-proto 1.1.0 mode/Mode#<UserModerust-analyzer cargo irc-proto 1.1.0 mode/UserMode#>>, MessageParseErrorrust-analyzer cargo irc-proto 1.1.0 error/MessageParseError#> {
286 parse_modesrust-analyzer cargo irc-proto 1.1.0 mode/parse_modes().(pieces)
287 }
288 }
289
290 // MODE channel [modes [modeparams]]
291 impl Moderust-analyzer cargo irc-proto 1.1.0 mode/Mode#<ChannelModerust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#> {
292 // TODO: turning more edge cases into errors.
293 /// Parses the specified mode string as channel modes.
294 pub fn as_channel_modesrust-analyzer cargo irc-proto 1.1.0 mode/impl#[`Mode<ChannelMode>`]as_channel_modes().(pieces: &[&str]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Moderust-analyzer cargo irc-proto 1.1.0 mode/Mode#<ChannelModerust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#>>, MessageParseErrorrust-analyzer cargo irc-proto 1.1.0 error/MessageParseError#> {
295 parse_modesrust-analyzer cargo irc-proto 1.1.0 mode/parse_modes().(pieces)
296 }
297 }
298
299 fn parse_modesrust-analyzer cargo irc-proto 1.1.0 mode/parse_modes().<T>(pieces: &[&str]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Moderust-analyzer cargo irc-proto 1.1.0 mode/Mode#<T>>, MessageParseErrorrust-analyzer cargo irc-proto 1.1.0 error/MessageParseError#>
300 where
301 T: ModeTyperust-analyzer cargo irc-proto 1.1.0 mode/ModeType#,
302 {
303 use selfrust-analyzer cargo irc-proto 1.1.0 mode/::PlusMinusrust-analyzer cargo irc-proto 1.1.0 mode/PlusMinus#::*;
304
305 let mut res = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![];
306
307 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((first, rest)) = pieces.split_firstrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]split_first().() {
308 let mut modes = first.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().();
309 let mut args = rest.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().();
310
311 let mut cur_mod = match modes.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Chars<'a>`][Iterator]next().() {
312 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#('+') => Plusrust-analyzer cargo irc-proto 1.1.0 mode/PlusMinus#Plus#,
313 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#('-') => Minusrust-analyzer cargo irc-proto 1.1.0 mode/PlusMinus#Minus#,
314 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(_) => {
315 // rewind modes
316 modes = first.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().();
317 NoPrefixrust-analyzer cargo irc-proto 1.1.0 mode/PlusMinus#NoPrefix#
318 }
319 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => {
320 // No modifier
321 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(res);
322 }
323 };
324
325 for c in modes {
326 match c {
327 '+' => cur_mod = Plusrust-analyzer cargo irc-proto 1.1.0 mode/PlusMinus#Plus#,
328 '-' => cur_mod = Minusrust-analyzer cargo irc-proto 1.1.0 mode/PlusMinus#Minus#,
329 _ => {
330 let mode = T::from_charrust-analyzer cargo irc-proto 1.1.0 mode/ModeType#from_char().(c);
331 let arg = if mode.takes_argrust-analyzer cargo irc-proto 1.1.0 mode/ModeType#takes_arg().() {
332 // TODO: if there's no arg, this should error
333 args.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]next().()
334 } else {
335 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
336 };
337 res.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(match cur_mod {
338 Plusrust-analyzer cargo irc-proto 1.1.0 mode/PlusMinus#Plus# => Moderust-analyzer cargo irc-proto 1.1.0 mode/Mode#::Plusrust-analyzer cargo irc-proto 1.1.0 mode/Mode#Plus#(mode, arg.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|s| s.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())),
339 Minusrust-analyzer cargo irc-proto 1.1.0 mode/PlusMinus#Minus# => Moderust-analyzer cargo irc-proto 1.1.0 mode/Mode#::Minusrust-analyzer cargo irc-proto 1.1.0 mode/Mode#Minus#(mode, arg.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|s| s.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())),
340 NoPrefixrust-analyzer cargo irc-proto 1.1.0 mode/PlusMinus#NoPrefix# => Moderust-analyzer cargo irc-proto 1.1.0 mode/Mode#::NoPrefixrust-analyzer cargo irc-proto 1.1.0 mode/Mode#NoPrefix#(mode),
341 })
342 }
343 }
344 }
345
346 // TODO: if there are extra args left, this should error
347 } else {
348 // No modifier
349 };
350
351 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(res)
352 }
353
354 #[cfg(test)]
355 mod testrust-analyzer cargo irc-proto 1.1.0 mode/test/ {
356 use superrust-analyzer cargo irc-proto 1.1.0 mode/::{ChannelModerust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#, Moderust-analyzer cargo irc-proto 1.1.0 mode/Mode#};
357 use craterust-analyzer cargo irc-proto 1.1.0 crate/::Commandrust-analyzer cargo irc-proto 1.1.0 command/Command#;
358 use craterust-analyzer cargo irc-proto 1.1.0 crate/::Messagerust-analyzer cargo irc-proto 1.1.0 message/Message#;
359
360 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
361 fn parse_channel_moderust-analyzer cargo irc-proto 1.1.0 mode/test/parse_channel_mode().() {
362 let cmd = "MODE #foo +r".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<Messagerust-analyzer cargo irc-proto 1.1.0 message/Message#>().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().commandrust-analyzer cargo irc-proto 1.1.0 message/Message#command.;
363 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
364 Commandrust-analyzer cargo irc-proto 1.1.0 command/Command#::ChannelMODErust-analyzer cargo irc-proto 1.1.0 command/Command#ChannelMODE#(
365 "#foo".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
366 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Moderust-analyzer cargo irc-proto 1.1.0 mode/Mode#::Plusrust-analyzer cargo irc-proto 1.1.0 mode/Mode#Plus#(ChannelModerust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#::RegisteredOnlyrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#RegisteredOnly#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#)]
367 ),
368 cmd
369 );
370 }
371
372 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
373 fn parse_no_moderust-analyzer cargo irc-proto 1.1.0 mode/test/parse_no_mode().() {
374 let cmd = "MODE #foo".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<Messagerust-analyzer cargo irc-proto 1.1.0 message/Message#>().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().commandrust-analyzer cargo irc-proto 1.1.0 message/Message#command.;
375 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Commandrust-analyzer cargo irc-proto 1.1.0 command/Command#::ChannelMODErust-analyzer cargo irc-proto 1.1.0 command/Command#ChannelMODE#("#foo".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]), cmd);
376 }
377
378 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
379 fn parse_no_plusrust-analyzer cargo irc-proto 1.1.0 mode/test/parse_no_plus().() {
380 let cmd = "MODE #foo b".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<Messagerust-analyzer cargo irc-proto 1.1.0 message/Message#>().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().commandrust-analyzer cargo irc-proto 1.1.0 message/Message#command.;
381 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
382 Commandrust-analyzer cargo irc-proto 1.1.0 command/Command#::ChannelMODErust-analyzer cargo irc-proto 1.1.0 command/Command#ChannelMODE#("#foo".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Moderust-analyzer cargo irc-proto 1.1.0 mode/Mode#::NoPrefixrust-analyzer cargo irc-proto 1.1.0 mode/Mode#NoPrefix#(ChannelModerust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#::Banrust-analyzer cargo irc-proto 1.1.0 mode/ChannelMode#Ban#)]),
383 cmd
384 );
385 }
386 }