1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use crate::{irc::*, MaybeOwned, Validator};

/// Signals that you should reconnect and rejoin channels after a restart.

///

/// Twitch IRC processes occasionally need to be restarted. When this happens,

/// clients that have requested the IRC v3 `twitch.tv/commands` _capability_ are

/// issued a `RECONNECT`. After a short time, the connection is closed. In this

/// case, reconnect and rejoin channels that were on the connection, as you

/// would normally.

#[derive(Clone, PartialEq)]
pub struct Reconnect<'a> {
    raw: MaybeOwned<'a>,
}

impl<'a> Reconnect<'a> {
    raw!();
}

impl<'a> FromIrcMessage<'a> for Reconnect<'a> {
    type Error = MessageError;

    fn from_irc(msg: IrcMessage<'a>) -> Result<Self, Self::Error> {
        msg.expect_command(IrcMessage::RECONNECT)?;
        Ok(Self { raw: msg.raw })
    }

    into_inner_raw!();
}

into_owned!(Reconnect { raw });
impl_custom_debug!(Reconnect { raw });
serde_struct!(Reconnect { raw });

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

    #[test]
    #[cfg(feature = "serde")]
    fn reconnect_serde() {
        let input = ":tmi.twitch.tv RECONNECT\r\n";
        crate::serde::round_trip_json::<Reconnect>(input);
        crate::serde::round_trip_rmp::<Reconnect>(input);
    }

    #[test]
    fn reconnect() {
        let input = ":tmi.twitch.tv RECONNECT\r\n";
        for msg in parse(input).map(|s| s.unwrap()) {
            let _msg = Reconnect::from_irc(msg).unwrap();
        }
    }
}