30 lines
873 B
Rust
30 lines
873 B
Rust
use crate::commands::{
|
|
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
|
ResponseParserError,
|
|
};
|
|
|
|
pub struct SendMessage;
|
|
|
|
impl Command for SendMessage {
|
|
type Response = ();
|
|
const COMMAND: &'static str = "sendmessage";
|
|
|
|
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
|
let channel = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
|
|
|
// TODO: SplitWhitespace::remainder() is unstable, use when stable
|
|
let message = parts.collect::<Vec<_>>().join(" ");
|
|
|
|
debug_assert!(!message.is_empty());
|
|
|
|
Ok((Request::SendMessage(channel.to_string(), message), ""))
|
|
}
|
|
|
|
fn parse_response(
|
|
parts: ResponseAttributes<'_>,
|
|
) -> Result<Self::Response, ResponseParserError> {
|
|
debug_assert!(parts.is_empty());
|
|
Ok(())
|
|
}
|
|
}
|