| 1 | //! A module providing a data structure for messages to and from IRC servers. |
| 2 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::ToOwnedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/ToOwned#; |
| 3 | 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/::{Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#, Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#, Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# as FmtResultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result#, Writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write#}; |
| 4 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#; |
| 5 | |
| 6 | use craterust-analyzer cargo irc-proto 1.1.0 crate/::chanrust-analyzer cargo irc-proto 1.1.0 chan/::ChannelExtrust-analyzer cargo irc-proto 1.1.0 chan/ChannelExt#; |
| 7 | 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#; |
| 8 | use craterust-analyzer cargo irc-proto 1.1.0 crate/::errorrust-analyzer cargo irc-proto 1.1.0 error/; |
| 9 | 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#, ProtocolErrorrust-analyzer cargo irc-proto 1.1.0 error/ProtocolError#}; |
| 10 | use craterust-analyzer cargo irc-proto 1.1.0 crate/::prefixrust-analyzer cargo irc-proto 1.1.0 prefix/::Prefixrust-analyzer cargo irc-proto 1.1.0 prefix/Prefix#; |
| 11 | |
| 12 | /// A data structure representing an IRC message according to the protocol specification. It |
| 13 | /// consists of a collection of IRCv3 tags, a prefix (describing the source of the message), and |
| 14 | /// the protocol command. If the command is unknown, it is treated as a special raw command that |
| 15 | /// consists of a collection of arguments and the special suffix argument. Otherwise, the command |
| 16 | /// is parsed into a more useful form as described in [`Command`]. |
| 17 | #[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:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 18 | pub struct Messagerust-analyzer cargo irc-proto 1.1.0 message/Message# { |
| 19 | /// Message tags as defined by [IRCv3.2](http://ircv3.net/specs/core/message-tags-3.2.html). |
| 20 | /// These tags are used to add extended information to the given message, and are commonly used |
| 21 | /// in IRCv3 extensions to the IRC protocol. |
| 22 | pub tagsrust-analyzer cargo irc-proto 1.1.0 message/Message#tags.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Tagrust-analyzer cargo irc-proto 1.1.0 message/Tag#>>, |
| 23 | /// The message prefix (or source) as defined by [RFC 2812](http://tools.ietf.org/html/rfc2812). |
| 24 | pub prefixrust-analyzer cargo irc-proto 1.1.0 message/Message#prefix.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Prefixrust-analyzer cargo irc-proto 1.1.0 prefix/Prefix#>, |
| 25 | /// The IRC command, parsed according to the known specifications. The command itself and its |
| 26 | /// arguments (including the special suffix argument) are captured in this component. |
| 27 | pub commandrust-analyzer cargo irc-proto 1.1.0 message/Message#command.: Commandrust-analyzer cargo irc-proto 1.1.0 command/Command#, |
| 28 | } |
| 29 | |
| 30 | impl Messagerust-analyzer cargo irc-proto 1.1.0 message/Message# { |
| 31 | /// Creates a new message from the given components. |
| 32 | /// |
| 33 | /// # Example |
| 34 | /// ``` |
| 35 | /// # extern crate irc_proto; |
| 36 | /// # use irc_proto::Message; |
| 37 | /// # fn main() { |
| 38 | /// let message = Message::new( |
| 39 | /// Some("nickname!username@hostname"), "JOIN", vec!["#channel"] |
| 40 | /// ).unwrap(); |
| 41 | /// # } |
| 42 | /// ``` |
| 43 | pub fn newrust-analyzer cargo irc-proto 1.1.0 message/impl#[Message]new().( |
| 44 | prefix: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str>, |
| 45 | command: &str, |
| 46 | args: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<&str>, |
| 47 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Messagerust-analyzer cargo irc-proto 1.1.0 message/Message#, MessageParseErrorrust-analyzer cargo irc-proto 1.1.0 error/MessageParseError#> { |
| 48 | Messagerust-analyzer cargo irc-proto 1.1.0 message/Message#::with_tagsrust-analyzer cargo irc-proto 1.1.0 message/impl#[Message]with_tags().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, prefix, command, args) |
| 49 | } |
| 50 | |
| 51 | /// Creates a new IRCv3.2 message from the given components, including message tags. These tags |
| 52 | /// are used to add extended information to the given message, and are commonly used in IRCv3 |
| 53 | /// extensions to the IRC protocol. |
| 54 | pub fn with_tagsrust-analyzer cargo irc-proto 1.1.0 message/impl#[Message]with_tags().( |
| 55 | tags: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Tagrust-analyzer cargo irc-proto 1.1.0 message/Tag#>>, |
| 56 | prefix: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str>, |
| 57 | command: &str, |
| 58 | args: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<&str>, |
| 59 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Messagerust-analyzer cargo irc-proto 1.1.0 message/Message#, errorrust-analyzer cargo irc-proto 1.1.0 error/::MessageParseErrorrust-analyzer cargo irc-proto 1.1.0 error/MessageParseError#> { |
| 60 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Messagerust-analyzer cargo irc-proto 1.1.0 message/Message# { |
| 61 | tagsrust-analyzer cargo irc-proto 1.1.0 message/Message#tags., |
| 62 | prefixrust-analyzer cargo irc-proto 1.1.0 message/Message#prefix.: prefix.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|p| p.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()), |
| 63 | commandrust-analyzer cargo irc-proto 1.1.0 message/Message#command.: Commandrust-analyzer cargo irc-proto 1.1.0 command/Command#::newrust-analyzer cargo irc-proto 1.1.0 command/impl#[Command]new().(command, args)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 64 | }) |
| 65 | } |
| 66 | |
| 67 | /// Gets the nickname of the message source, if it exists. |
| 68 | /// |
| 69 | /// # Example |
| 70 | /// ``` |
| 71 | /// # extern crate irc_proto; |
| 72 | /// # use irc_proto::Message; |
| 73 | /// # fn main() { |
| 74 | /// let message = Message::new( |
| 75 | /// Some("nickname!username@hostname"), "JOIN", vec!["#channel"] |
| 76 | /// ).unwrap(); |
| 77 | /// assert_eq!(message.source_nickname(), Some("nickname")); |
| 78 | /// # } |
| 79 | /// ``` |
| 80 | pub fn source_nicknamerust-analyzer cargo irc-proto 1.1.0 message/impl#[Message]source_nickname().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str> { |
| 81 | // <prefix> ::= <servername> | <nick> [ '!' <user> ] [ '@' <host> ] |
| 82 | // <servername> ::= <host> |
| 83 | self.prefixrust-analyzer cargo irc-proto 1.1.0 message/Message#prefix..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|p| match p { |
| 84 | Prefixrust-analyzer cargo irc-proto 1.1.0 prefix/Prefix#::Nicknamerust-analyzer cargo irc-proto 1.1.0 prefix/Prefix#Nickname#(name, _, _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&name[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().), |
| 85 | _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 86 | }) |
| 87 | } |
| 88 | |
| 89 | /// Gets the likely intended place to respond to this message. |
| 90 | /// If the type of the message is a `PRIVMSG` or `NOTICE` and the message is sent to a channel, |
| 91 | /// the result will be that channel. In all other cases, this will call `source_nickname`. |
| 92 | /// |
| 93 | /// # Example |
| 94 | /// ``` |
| 95 | /// # extern crate irc_proto; |
| 96 | /// # use irc_proto::Message; |
| 97 | /// # fn main() { |
| 98 | /// let msg1 = Message::new( |
| 99 | /// Some("ada"), "PRIVMSG", vec!["#channel", "Hi, everyone!"] |
| 100 | /// ).unwrap(); |
| 101 | /// assert_eq!(msg1.response_target(), Some("#channel")); |
| 102 | /// let msg2 = Message::new( |
| 103 | /// Some("ada"), "PRIVMSG", vec!["betsy", "betsy: hi"] |
| 104 | /// ).unwrap(); |
| 105 | /// assert_eq!(msg2.response_target(), Some("ada")); |
| 106 | /// # } |
| 107 | /// ``` |
| 108 | pub fn response_targetrust-analyzer cargo irc-proto 1.1.0 message/impl#[Message]response_target().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str> { |
| 109 | match self.commandrust-analyzer cargo irc-proto 1.1.0 message/Message#command. { |
| 110 | Commandrust-analyzer cargo irc-proto 1.1.0 command/Command#::PRIVMSGrust-analyzer cargo irc-proto 1.1.0 command/Command#PRIVMSG#(ref target, _) if target.is_channel_namerust-analyzer cargo irc-proto 1.1.0 chan/impl#[String][ChannelExt]is_channel_name().() => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(target), |
| 111 | Commandrust-analyzer cargo irc-proto 1.1.0 command/Command#::NOTICErust-analyzer cargo irc-proto 1.1.0 command/Command#NOTICE#(ref target, _) if target.is_channel_namerust-analyzer cargo irc-proto 1.1.0 chan/impl#[String][ChannelExt]is_channel_name().() => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(target), |
| 112 | _ => self.source_nicknamerust-analyzer cargo irc-proto 1.1.0 message/impl#[Message]source_nickname().(), |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<Commandrust-analyzer cargo irc-proto 1.1.0 command/Command#> for Messagerust-analyzer cargo irc-proto 1.1.0 message/Message# { |
| 118 | fn fromrust-analyzer cargo irc-proto 1.1.0 message/impl#[Message][`From<Command>`]from().(cmd: Commandrust-analyzer cargo irc-proto 1.1.0 command/Command#) -> Messagerust-analyzer cargo irc-proto 1.1.0 message/Message# { |
| 119 | Messagerust-analyzer cargo irc-proto 1.1.0 message/Message# { |
| 120 | tagsrust-analyzer cargo irc-proto 1.1.0 message/Message#tags.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 121 | prefixrust-analyzer cargo irc-proto 1.1.0 message/Message#prefix.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 122 | commandrust-analyzer cargo irc-proto 1.1.0 message/Message#command.: cmd, |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | impl FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr# for Messagerust-analyzer cargo irc-proto 1.1.0 message/Message# { |
| 128 | type Errrust-analyzer cargo irc-proto 1.1.0 message/impl#[Message][FromStr]Err# = ProtocolErrorrust-analyzer cargo irc-proto 1.1.0 error/ProtocolError#; |
| 129 | |
| 130 | fn from_strrust-analyzer cargo irc-proto 1.1.0 message/impl#[Message][FromStr]from_str().(s: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Messagerust-analyzer cargo irc-proto 1.1.0 message/Message#, Selfrust-analyzer cargo irc-proto 1.1.0 message/impl#[Message][FromStr]::Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#Err#> { |
| 131 | if s.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() { |
| 132 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ProtocolErrorrust-analyzer cargo irc-proto 1.1.0 error/ProtocolError#::InvalidMessagerust-analyzer cargo irc-proto 1.1.0 error/ProtocolError#InvalidMessage# { |
| 133 | stringrust-analyzer cargo irc-proto 1.1.0 error/ProtocolError#InvalidMessage#string.: s.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 134 | causerust-analyzer cargo irc-proto 1.1.0 error/ProtocolError#InvalidMessage#cause.: MessageParseErrorrust-analyzer cargo irc-proto 1.1.0 error/MessageParseError#::EmptyMessagerust-analyzer cargo irc-proto 1.1.0 error/MessageParseError#EmptyMessage#, |
| 135 | }); |
| 136 | } |
| 137 | |
| 138 | let mut state = s; |
| 139 | |
| 140 | let tags = if state.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().('@') { |
| 141 | let tags = state.findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().(' ').maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|i| &state[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().); |
| 142 | state = state.findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().(' ').map_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map_or().("", |i| &state[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().); |
| 143 | tags.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|ts| { |
| 144 | ts.splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().(';') |
| 145 | .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|s| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().s.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().()) |
| 146 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|s: &str| { |
| 147 | let mut iter = s.splitnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]splitn().(2, '='); |
| 148 | let (fst, snd) = (iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`SplitN<'a, P>`][Iterator]next().(), iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`SplitN<'a, P>`][Iterator]next().()); |
| 149 | let snd = snd.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(unescape_tag_valuerust-analyzer cargo irc-proto 1.1.0 message/unescape_tag_value().); |
| 150 | Tagrust-analyzer cargo irc-proto 1.1.0 message/Tag#(fst.unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().("").to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), snd) |
| 151 | }) |
| 152 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>() |
| 153 | }) |
| 154 | } else { |
| 155 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 156 | }; |
| 157 | |
| 158 | let prefix = if state.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().(':') { |
| 159 | let prefix = state.findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().(' ').maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|i| &state[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().); |
| 160 | state = state.findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().(' ').map_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map_or().("", |i| &state[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().); |
| 161 | prefix |
| 162 | } else { |
| 163 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 164 | }; |
| 165 | |
| 166 | let line_ending_len = if state.ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]ends_with().("\r\n") { |
| 167 | "\r\n" |
| 168 | } else if state.ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]ends_with().('\r') { |
| 169 | "\r" |
| 170 | } else if state.ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]ends_with().('\n') { |
| 171 | "\n" |
| 172 | } else { |
| 173 | "" |
| 174 | } |
| 175 | .lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().(); |
| 176 | |
| 177 | let suffix = if state.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().(" :") { |
| 178 | let suffix = state |
| 179 | .findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().(" :") |
| 180 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|i| &state[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().2..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#state.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().line_ending_len]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().); |
| 181 | state = state.findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().(" :").map_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map_or().("", |i| &state[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().); |
| 182 | suffix |
| 183 | } else { |
| 184 | state = &state[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#state.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().line_ending_len]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 185 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 186 | }; |
| 187 | |
| 188 | let command = match state.findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().(' ').maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|i| &state[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().) { |
| 189 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(cmd) => { |
| 190 | state = state.findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().(' ').map_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map_or().("", |i| &state[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().); |
| 191 | cmd |
| 192 | } |
| 193 | // If there's no arguments but the "command" starts with colon, it's not a command. |
| 194 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# if state.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().(':') => { |
| 195 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ProtocolErrorrust-analyzer cargo irc-proto 1.1.0 error/ProtocolError#::InvalidMessagerust-analyzer cargo irc-proto 1.1.0 error/ProtocolError#InvalidMessage# { |
| 196 | stringrust-analyzer cargo irc-proto 1.1.0 error/ProtocolError#InvalidMessage#string.: s.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 197 | causerust-analyzer cargo irc-proto 1.1.0 error/ProtocolError#InvalidMessage#cause.: MessageParseErrorrust-analyzer cargo irc-proto 1.1.0 error/MessageParseError#::InvalidCommandrust-analyzer cargo irc-proto 1.1.0 error/MessageParseError#InvalidCommand#, |
| 198 | }) |
| 199 | } |
| 200 | // If there's no arguments following the command, the rest of the state is the command. |
| 201 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => { |
| 202 | let cmd = state; |
| 203 | state = ""; |
| 204 | cmd |
| 205 | } |
| 206 | }; |
| 207 | |
| 208 | let mut args: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = state.splitnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]splitn().(14, ' ').filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|s| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().s.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 209 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(suffix) = suffix { |
| 210 | args.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(suffix); |
| 211 | } |
| 212 | |
| 213 | Messagerust-analyzer cargo irc-proto 1.1.0 message/Message#::with_tagsrust-analyzer cargo irc-proto 1.1.0 message/impl#[Message]with_tags().(tags, prefix, command, args).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| ProtocolErrorrust-analyzer cargo irc-proto 1.1.0 error/ProtocolError#::InvalidMessagerust-analyzer cargo irc-proto 1.1.0 error/ProtocolError#InvalidMessage# { |
| 214 | stringrust-analyzer cargo irc-proto 1.1.0 error/ProtocolError#InvalidMessage#string.: s.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 215 | causerust-analyzer cargo irc-proto 1.1.0 error/ProtocolError#InvalidMessage#cause.: e, |
| 216 | }) |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | impl<'a> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<&'a str> for Messagerust-analyzer cargo irc-proto 1.1.0 message/Message# { |
| 221 | fn fromrust-analyzer cargo irc-proto 1.1.0 message/impl#[Message][`From<&'a str>`]from().(s: &'a str) -> Messagerust-analyzer cargo irc-proto 1.1.0 message/Message# { |
| 222 | s.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | impl Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for Messagerust-analyzer cargo irc-proto 1.1.0 message/Message# { |
| 227 | /// Converts a Message into a String according to the IRC protocol. |
| 228 | /// |
| 229 | /// # Example |
| 230 | /// ``` |
| 231 | /// # extern crate irc_proto; |
| 232 | /// # use irc_proto::Message; |
| 233 | /// # fn main() { |
| 234 | /// let msg = Message::new( |
| 235 | /// Some("ada"), "PRIVMSG", vec!["#channel", "Hi, everyone!"] |
| 236 | /// ).unwrap(); |
| 237 | /// assert_eq!(msg.to_string(), ":ada PRIVMSG #channel :Hi, everyone!\r\n"); |
| 238 | /// # } |
| 239 | /// ``` |
| 240 | fn fmtrust-analyzer cargo irc-proto 1.1.0 message/impl#[Message][Display]fmt().(&self, f: &mut Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> FmtResultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 241 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref tags) = self.tagsrust-analyzer cargo irc-proto 1.1.0 message/Message#tags. { |
| 242 | f.write_charrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'_>`][Write]write_char().('@')?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 243 | for (i, tag) in tags.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() { |
| 244 | if i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 { |
| 245 | f.write_charrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'_>`][Write]write_char().(';')?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 246 | } |
| 247 | f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().(&tag.0rust-analyzer cargo irc-proto 1.1.0 message/Tag#0.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 248 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref value) = tag.1rust-analyzer cargo irc-proto 1.1.0 message/Tag#1. { |
| 249 | f.write_charrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'_>`][Write]write_char().('=')?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 250 | escape_tag_valuerust-analyzer cargo irc-proto 1.1.0 message/escape_tag_value().(f, value)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 251 | } |
| 252 | } |
| 253 | f.write_charrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'_>`][Write]write_char().(' ')?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 254 | } |
| 255 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref prefix) = self.prefixrust-analyzer cargo irc-proto 1.1.0 message/Message#prefix. { |
| 256 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, ":{} ", prefix)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). |
| 257 | } |
| 258 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{}\r\n", Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::fromrust-analyzer cargo irc-proto 1.1.0 command/impl#[String][`From<&'a Command>`]from().(&self.commandrust-analyzer cargo irc-proto 1.1.0 message/Message#command.)) |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | /// A message tag as defined by [IRCv3.2](http://ircv3.net/specs/core/message-tags-3.2.html). |
| 263 | /// It consists of a tag key, and an optional value for the tag. Each message can contain a number |
| 264 | /// of tags (in the string format, they are separated by semicolons). Tags are used to add extended |
| 265 | /// information to a message under IRCv3. |
| 266 | #[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:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 267 | pub struct Tagrust-analyzer cargo irc-proto 1.1.0 message/Tag#(pub Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, pub 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#>); |
| 268 | |
| 269 | fn escape_tag_valuerust-analyzer cargo irc-proto 1.1.0 message/escape_tag_value().(f: &mut dyn Writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write#, value: &str) -> FmtResultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 270 | for c in value.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().() { |
| 271 | match c { |
| 272 | ';' => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write#write_str().("\\:")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 273 | ' ' => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write#write_str().("\\s")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 274 | '\\' => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write#write_str().("\\\\")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 275 | '\r' => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write#write_str().("\\r")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 276 | '\n' => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write#write_str().("\\n")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 277 | c => f.write_charrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write#write_char().(c)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 278 | } |
| 279 | } |
| 280 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 281 | } |
| 282 | |
| 283 | fn unescape_tag_valuerust-analyzer cargo irc-proto 1.1.0 message/unescape_tag_value().(value: &str) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 284 | let mut unescaped = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]with_capacity().(value.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().()); |
| 285 | let mut iter = value.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().(); |
| 286 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(c) = iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Chars<'a>`][Iterator]next().() { |
| 287 | let r = if c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'\\' { |
| 288 | match iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Chars<'a>`][Iterator]next().() { |
| 289 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(':') => ';', |
| 290 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#('s') => ' ', |
| 291 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#('\\') => '\\', |
| 292 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#('r') => '\r', |
| 293 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#('n') => '\n', |
| 294 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(c) => c, |
| 295 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => break, |
| 296 | } |
| 297 | } else { |
| 298 | c |
| 299 | }; |
| 300 | unescaped.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().(r); |
| 301 | } |
| 302 | unescaped |
| 303 | } |
| 304 | |
| 305 | #[cfg(test)] |
| 306 | mod testrust-analyzer cargo irc-proto 1.1.0 message/test/ { |
| 307 | use superrust-analyzer cargo irc-proto 1.1.0 message/::{Messagerust-analyzer cargo irc-proto 1.1.0 message/Message#, Tagrust-analyzer cargo irc-proto 1.1.0 message/Tag#}; |
| 308 | 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#::{Rawrust-analyzer cargo irc-proto 1.1.0 command/Command#Raw#, PRIVMSGrust-analyzer cargo irc-proto 1.1.0 command/Command#PRIVMSG#, QUITrust-analyzer cargo irc-proto 1.1.0 command/Command#QUIT#}; |
| 309 | |
| 310 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 311 | fn newrust-analyzer cargo irc-proto 1.1.0 message/test/new().() { |
| 312 | let message = Messagerust-analyzer cargo irc-proto 1.1.0 message/Message# { |
| 313 | tagsrust-analyzer cargo irc-proto 1.1.0 message/Message#tags.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 314 | prefixrust-analyzer cargo irc-proto 1.1.0 message/Message#prefix.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 315 | commandrust-analyzer cargo irc-proto 1.1.0 message/Message#command.: PRIVMSGrust-analyzer cargo irc-proto 1.1.0 command/Command#PRIVMSG#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("test"), formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Testing!")), |
| 316 | }; |
| 317 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 318 | Messagerust-analyzer cargo irc-proto 1.1.0 message/Message#::newrust-analyzer cargo irc-proto 1.1.0 message/impl#[Message]new().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, "PRIVMSG", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["test", "Testing!"]).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 319 | message |
| 320 | ) |
| 321 | } |
| 322 | |
| 323 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 324 | fn source_nicknamerust-analyzer cargo irc-proto 1.1.0 message/test/source_nickname().() { |
| 325 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 326 | Messagerust-analyzer cargo irc-proto 1.1.0 message/Message#::newrust-analyzer cargo irc-proto 1.1.0 message/impl#[Message]new().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, "PING", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["data"]) |
| 327 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() |
| 328 | .source_nicknamerust-analyzer cargo irc-proto 1.1.0 message/impl#[Message]source_nickname().(), |
| 329 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 330 | ); |
| 331 | |
| 332 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 333 | Messagerust-analyzer cargo irc-proto 1.1.0 message/Message#::newrust-analyzer cargo irc-proto 1.1.0 message/impl#[Message]new().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("irc.test.net"), "PING", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["data"]) |
| 334 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() |
| 335 | .source_nicknamerust-analyzer cargo irc-proto 1.1.0 message/impl#[Message]source_nickname().(), |
| 336 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 337 | ); |
| 338 | |
| 339 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 340 | Messagerust-analyzer cargo irc-proto 1.1.0 message/Message#::newrust-analyzer cargo irc-proto 1.1.0 message/impl#[Message]new().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("test!test@test"), "PING", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["data"]) |
| 341 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() |
| 342 | .source_nicknamerust-analyzer cargo irc-proto 1.1.0 message/impl#[Message]source_nickname().(), |
| 343 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("test") |
| 344 | ); |
| 345 | |
| 346 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 347 | Messagerust-analyzer cargo irc-proto 1.1.0 message/Message#::newrust-analyzer cargo irc-proto 1.1.0 message/impl#[Message]new().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("test@test"), "PING", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["data"]) |
| 348 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() |
| 349 | .source_nicknamerust-analyzer cargo irc-proto 1.1.0 message/impl#[Message]source_nickname().(), |
| 350 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("test") |
| 351 | ); |
| 352 | |
| 353 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 354 | Messagerust-analyzer cargo irc-proto 1.1.0 message/Message#::newrust-analyzer cargo irc-proto 1.1.0 message/impl#[Message]new().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("[email protected]"), "PING", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["data"]) |
| 355 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() |
| 356 | .source_nicknamerust-analyzer cargo irc-proto 1.1.0 message/impl#[Message]source_nickname().(), |
| 357 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("test") |
| 358 | ); |
| 359 | |
| 360 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 361 | Messagerust-analyzer cargo irc-proto 1.1.0 message/Message#::newrust-analyzer cargo irc-proto 1.1.0 message/impl#[Message]new().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("[email protected]"), "PING", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["data"]) |
| 362 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() |
| 363 | .source_nicknamerust-analyzer cargo irc-proto 1.1.0 message/impl#[Message]source_nickname().(), |
| 364 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("test") |
| 365 | ); |
| 366 | |
| 367 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 368 | Messagerust-analyzer cargo irc-proto 1.1.0 message/Message#::newrust-analyzer cargo irc-proto 1.1.0 message/impl#[Message]new().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("[email protected]"), "PING", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["data"]) |
| 369 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() |
| 370 | .source_nicknamerust-analyzer cargo irc-proto 1.1.0 message/impl#[Message]source_nickname().(), |
| 371 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("test") |
| 372 | ); |
| 373 | |
| 374 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 375 | Messagerust-analyzer cargo irc-proto 1.1.0 message/Message#::newrust-analyzer cargo irc-proto 1.1.0 message/impl#[Message]new().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("test"), "PING", vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["data"]) |
| 376 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() |
| 377 | .source_nicknamerust-analyzer cargo irc-proto 1.1.0 message/impl#[Message]source_nickname().(), |
| 378 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("test") |
| 379 | ); |
| 380 | } |
| 381 | |
| 382 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 383 | fn to_stringrust-analyzer cargo irc-proto 1.1.0 message/test/to_string().() { |
| 384 | let message = Messagerust-analyzer cargo irc-proto 1.1.0 message/Message# { |
| 385 | tagsrust-analyzer cargo irc-proto 1.1.0 message/Message#tags.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 386 | prefixrust-analyzer cargo irc-proto 1.1.0 message/Message#prefix.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 387 | commandrust-analyzer cargo irc-proto 1.1.0 message/Message#command.: PRIVMSGrust-analyzer cargo irc-proto 1.1.0 command/Command#PRIVMSG#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("test"), formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Testing!")), |
| 388 | }; |
| 389 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&message.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()...]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()., "PRIVMSG test Testing!\r\n"); |
| 390 | let message = Messagerust-analyzer cargo irc-proto 1.1.0 message/Message# { |
| 391 | tagsrust-analyzer cargo irc-proto 1.1.0 message/Message#tags.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 392 | prefixrust-analyzer cargo irc-proto 1.1.0 message/Message#prefix.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("test!test@test".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()), |
| 393 | commandrust-analyzer cargo irc-proto 1.1.0 message/Message#command.: PRIVMSGrust-analyzer cargo irc-proto 1.1.0 command/Command#PRIVMSG#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("test"), formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Still testing!")), |
| 394 | }; |
| 395 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 396 | &message.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()...]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()., |
| 397 | ":test!test@test PRIVMSG test :Still testing!\r\n" |
| 398 | ); |
| 399 | } |
| 400 | |
| 401 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 402 | fn from_stringrust-analyzer cargo irc-proto 1.1.0 message/test/from_string().() { |
| 403 | let message = Messagerust-analyzer cargo irc-proto 1.1.0 message/Message# { |
| 404 | tagsrust-analyzer cargo irc-proto 1.1.0 message/Message#tags.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 405 | prefixrust-analyzer cargo irc-proto 1.1.0 message/Message#prefix.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 406 | commandrust-analyzer cargo irc-proto 1.1.0 message/Message#command.: PRIVMSGrust-analyzer cargo irc-proto 1.1.0 command/Command#PRIVMSG#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("test"), formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Testing!")), |
| 407 | }; |
| 408 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 409 | "PRIVMSG test :Testing!\r\n".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().(), |
| 410 | message |
| 411 | ); |
| 412 | let message = Messagerust-analyzer cargo irc-proto 1.1.0 message/Message# { |
| 413 | tagsrust-analyzer cargo irc-proto 1.1.0 message/Message#tags.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 414 | prefixrust-analyzer cargo irc-proto 1.1.0 message/Message#prefix.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("test!test@test".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()), |
| 415 | commandrust-analyzer cargo irc-proto 1.1.0 message/Message#command.: PRIVMSGrust-analyzer cargo irc-proto 1.1.0 command/Command#PRIVMSG#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("test"), formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Still testing!")), |
| 416 | }; |
| 417 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 418 | ":test!test@test PRIVMSG test :Still testing!\r\n" |
| 419 | .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#>() |
| 420 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 421 | message |
| 422 | ); |
| 423 | let message = Messagerust-analyzer cargo irc-proto 1.1.0 message/Message# { |
| 424 | tagsrust-analyzer cargo irc-proto 1.1.0 message/Message#tags.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 425 | Tagrust-analyzer cargo irc-proto 1.1.0 message/Tag#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("aaa"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("bbb"))), |
| 426 | Tagrust-analyzer cargo irc-proto 1.1.0 message/Tag#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("ccc"), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#), |
| 427 | Tagrust-analyzer cargo irc-proto 1.1.0 message/Tag#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("example.com/ddd"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("eee"))), |
| 428 | ]), |
| 429 | prefixrust-analyzer cargo irc-proto 1.1.0 message/Message#prefix.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("test!test@test".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()), |
| 430 | commandrust-analyzer cargo irc-proto 1.1.0 message/Message#command.: PRIVMSGrust-analyzer cargo irc-proto 1.1.0 command/Command#PRIVMSG#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("test"), formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Testing with tags!")), |
| 431 | }; |
| 432 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 433 | "@aaa=bbb;ccc;example.com/ddd=eee :test!test@test PRIVMSG test :Testing with \ |
| 434 | tags!\r\n" |
| 435 | .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#>() |
| 436 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 437 | message |
| 438 | ) |
| 439 | } |
| 440 | |
| 441 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 442 | fn from_string_atypical_endingsrust-analyzer cargo irc-proto 1.1.0 message/test/from_string_atypical_endings().() { |
| 443 | let message = Messagerust-analyzer cargo irc-proto 1.1.0 message/Message# { |
| 444 | tagsrust-analyzer cargo irc-proto 1.1.0 message/Message#tags.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 445 | prefixrust-analyzer cargo irc-proto 1.1.0 message/Message#prefix.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 446 | commandrust-analyzer cargo irc-proto 1.1.0 message/Message#command.: PRIVMSGrust-analyzer cargo irc-proto 1.1.0 command/Command#PRIVMSG#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("test"), formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Testing!")), |
| 447 | }; |
| 448 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 449 | "PRIVMSG test :Testing!\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().(), |
| 450 | message |
| 451 | ); |
| 452 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 453 | "PRIVMSG test :Testing!\n".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().(), |
| 454 | message |
| 455 | ); |
| 456 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 457 | "PRIVMSG test :Testing!".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().(), |
| 458 | message |
| 459 | ); |
| 460 | } |
| 461 | |
| 462 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 463 | fn from_and_to_stringrust-analyzer cargo irc-proto 1.1.0 message/test/from_and_to_string().() { |
| 464 | let message = |
| 465 | "@aaa=bbb;ccc;example.com/ddd=eee :test!test@test PRIVMSG test :Testing with \ |
| 466 | tags!\r\n"; |
| 467 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(message.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().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), message); |
| 468 | } |
| 469 | |
| 470 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 471 | fn to_messagerust-analyzer cargo irc-proto 1.1.0 message/test/to_message().() { |
| 472 | let message = Messagerust-analyzer cargo irc-proto 1.1.0 message/Message# { |
| 473 | tagsrust-analyzer cargo irc-proto 1.1.0 message/Message#tags.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 474 | prefixrust-analyzer cargo irc-proto 1.1.0 message/Message#prefix.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 475 | commandrust-analyzer cargo irc-proto 1.1.0 message/Message#command.: PRIVMSGrust-analyzer cargo irc-proto 1.1.0 command/Command#PRIVMSG#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("test"), formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Testing!")), |
| 476 | }; |
| 477 | let msg: Messagerust-analyzer cargo irc-proto 1.1.0 message/Message# = "PRIVMSG test :Testing!\r\n".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(); |
| 478 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(msg, message); |
| 479 | let message = Messagerust-analyzer cargo irc-proto 1.1.0 message/Message# { |
| 480 | tagsrust-analyzer cargo irc-proto 1.1.0 message/Message#tags.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 481 | prefixrust-analyzer cargo irc-proto 1.1.0 message/Message#prefix.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("test!test@test".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()), |
| 482 | commandrust-analyzer cargo irc-proto 1.1.0 message/Message#command.: PRIVMSGrust-analyzer cargo irc-proto 1.1.0 command/Command#PRIVMSG#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("test"), formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Still testing!")), |
| 483 | }; |
| 484 | let msg: Messagerust-analyzer cargo irc-proto 1.1.0 message/Message# = ":test!test@test PRIVMSG test :Still testing!\r\n".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(); |
| 485 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(msg, message); |
| 486 | } |
| 487 | |
| 488 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 489 | fn to_message_with_colon_in_argrust-analyzer cargo irc-proto 1.1.0 message/test/to_message_with_colon_in_arg().() { |
| 490 | // Apparently, UnrealIRCd (and perhaps some others) send some messages that include |
| 491 | // colons within individual parameters. So, let's make sure it parses correctly. |
| 492 | let message = Messagerust-analyzer cargo irc-proto 1.1.0 message/Message# { |
| 493 | tagsrust-analyzer cargo irc-proto 1.1.0 message/Message#tags.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 494 | prefixrust-analyzer cargo irc-proto 1.1.0 message/Message#prefix.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("test!test@test".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()), |
| 495 | commandrust-analyzer cargo irc-proto 1.1.0 message/Message#command.: Rawrust-analyzer cargo irc-proto 1.1.0 command/Command#Raw#( |
| 496 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("COMMAND"), |
| 497 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("ARG:test"), formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Testing!")], |
| 498 | ), |
| 499 | }; |
| 500 | let msg: Messagerust-analyzer cargo irc-proto 1.1.0 message/Message# = ":test!test@test COMMAND ARG:test :Testing!\r\n".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(); |
| 501 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(msg, message); |
| 502 | } |
| 503 | |
| 504 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 505 | fn to_message_no_prefix_no_argsrust-analyzer cargo irc-proto 1.1.0 message/test/to_message_no_prefix_no_args().() { |
| 506 | let message = Messagerust-analyzer cargo irc-proto 1.1.0 message/Message# { |
| 507 | tagsrust-analyzer cargo irc-proto 1.1.0 message/Message#tags.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 508 | prefixrust-analyzer cargo irc-proto 1.1.0 message/Message#prefix.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 509 | commandrust-analyzer cargo irc-proto 1.1.0 message/Message#command.: QUITrust-analyzer cargo irc-proto 1.1.0 command/Command#QUIT#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#), |
| 510 | }; |
| 511 | let msg: Messagerust-analyzer cargo irc-proto 1.1.0 message/Message# = "QUIT\r\n".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(); |
| 512 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(msg, message); |
| 513 | } |
| 514 | |
| 515 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 516 | #[should_panic] |
| 517 | fn to_message_invalid_formatrust-analyzer cargo irc-proto 1.1.0 message/test/to_message_invalid_format().() { |
| 518 | let _: Messagerust-analyzer cargo irc-proto 1.1.0 message/Message# = ":invalid :message".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(); |
| 519 | } |
| 520 | |
| 521 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 522 | fn to_message_tags_escapesrust-analyzer cargo irc-proto 1.1.0 message/test/to_message_tags_escapes().() { |
| 523 | let msg = "@tag=\\:\\s\\\\\\r\\n\\a\\ :test PRIVMSG #test :test\r\n" |
| 524 | .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#>() |
| 525 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 526 | let message = Messagerust-analyzer cargo irc-proto 1.1.0 message/Message# { |
| 527 | tagsrust-analyzer cargo irc-proto 1.1.0 message/Message#tags.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Tagrust-analyzer cargo irc-proto 1.1.0 message/Tag#("tag".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("; \\\r\na".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()))]), |
| 528 | prefixrust-analyzer cargo irc-proto 1.1.0 message/Message#prefix.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("test".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()), |
| 529 | commandrust-analyzer cargo irc-proto 1.1.0 message/Message#command.: PRIVMSGrust-analyzer cargo irc-proto 1.1.0 command/Command#PRIVMSG#("#test".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "test".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()), |
| 530 | }; |
| 531 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(msg, message); |
| 532 | } |
| 533 | |
| 534 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 535 | fn to_string_tags_escapesrust-analyzer cargo irc-proto 1.1.0 message/test/to_string_tags_escapes().() { |
| 536 | let msg = Messagerust-analyzer cargo irc-proto 1.1.0 message/Message# { |
| 537 | tagsrust-analyzer cargo irc-proto 1.1.0 message/Message#tags.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Tagrust-analyzer cargo irc-proto 1.1.0 message/Tag#("tag".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("; \\\r\na".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()))]), |
| 538 | prefixrust-analyzer cargo irc-proto 1.1.0 message/Message#prefix.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("test".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()), |
| 539 | commandrust-analyzer cargo irc-proto 1.1.0 message/Message#command.: PRIVMSGrust-analyzer cargo irc-proto 1.1.0 command/Command#PRIVMSG#("#test".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "test".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()), |
| 540 | } |
| 541 | .to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 542 | let message = "@tag=\\:\\s\\\\\\r\\na :test PRIVMSG #test test\r\n"; |
| 543 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(msg, message); |
| 544 | } |
| 545 | |
| 546 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 547 | fn to_message_with_colon_in_suffixrust-analyzer cargo irc-proto 1.1.0 message/test/to_message_with_colon_in_suffix().() { |
| 548 | let msg = "PRIVMSG #test ::test".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().(); |
| 549 | let message = Messagerust-analyzer cargo irc-proto 1.1.0 message/Message# { |
| 550 | tagsrust-analyzer cargo irc-proto 1.1.0 message/Message#tags.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 551 | prefixrust-analyzer cargo irc-proto 1.1.0 message/Message#prefix.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 552 | commandrust-analyzer cargo irc-proto 1.1.0 message/Message#command.: PRIVMSGrust-analyzer cargo irc-proto 1.1.0 command/Command#PRIVMSG#("#test".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), ":test".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()), |
| 553 | }; |
| 554 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(msg, message); |
| 555 | } |
| 556 | |
| 557 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 558 | fn to_string_with_colon_in_suffixrust-analyzer cargo irc-proto 1.1.0 message/test/to_string_with_colon_in_suffix().() { |
| 559 | let msg = Messagerust-analyzer cargo irc-proto 1.1.0 message/Message# { |
| 560 | tagsrust-analyzer cargo irc-proto 1.1.0 message/Message#tags.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 561 | prefixrust-analyzer cargo irc-proto 1.1.0 message/Message#prefix.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 562 | commandrust-analyzer cargo irc-proto 1.1.0 message/Message#command.: PRIVMSGrust-analyzer cargo irc-proto 1.1.0 command/Command#PRIVMSG#("#test".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), ":test".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()), |
| 563 | } |
| 564 | .to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 565 | let message = "PRIVMSG #test ::test\r\n"; |
| 566 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(msg, message); |
| 567 | } |
| 568 | } |