1
use crate::commands::{
2
    Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
3
    ResponseParserError,
4
};
5

            
6
pub struct SendMessage;
7

            
8
impl Command for SendMessage {
9
    type Response = ();
10
    const COMMAND: &'static str = "sendmessage";
11

            
12
    fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
13
        let channel = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
14

            
15
        // TODO: SplitWhitespace::remainder() is unstable, use when stable
16
        let message = parts.collect::<Vec<_>>().join(" ");
17

            
18
        debug_assert!(!message.is_empty());
19

            
20
        Ok((Request::SendMessage(channel.to_string(), message), ""))
21
    }
22

            
23
    fn parse_response(
24
        parts: ResponseAttributes<'_>,
25
    ) -> Result<Self::Response, ResponseParserError> {
26
        debug_assert!(parts.is_empty());
27
        Ok(())
28
    }
29
}