/
akmitrich
/
udith
Обзор
Документация
Войти
/
akmitrich
/
udith
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/message/method.rs
45 строк
1 KB
akmitrich
refactor: Clean up 1.90 warnings
25 окт 2025, 17:45
25 окт 2025, 17:45
38d6cef
Код
Авторство
О чём код?
use crate::parse_utils::{ParseResult, token}; #[derive(Debug, Clone, Copy, PartialEq)] pub enum Method { Invite, Unknown, } impl TryFrom<&[u8]> for Method { type Error = crate::Error; fn try_from(value: &[u8]) -> crate::Result<Self> { let s = std::str::from_utf8(value)?; match s { "INVITE" => Ok(Self::Invite), _ => Ok(Self::Unknown), } } } impl Method { pub fn parse(src: &'_ [u8]) -> ParseResult<'_, Self> { let (rest, method_name) = token(src)?; match Self::try_from(method_name) { Ok(method) => Ok((rest, method)), Err(_) => Err(nom::Err::Error(nom::error::make_error( src, nom::error::ErrorKind::Fail, ))), } } } impl std::fmt::Display for Method { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!( f, "{}", match self { Method::Invite => "INVITE", Method::Unknown => "Unknown", } ) } }