/
akmitrich
/
udith
Обзор
Документация
Войти
/
akmitrich
/
udith
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/message/uri/userparam.rs
37 строк
930 B
akmitrich
refactor: Migrate to nom version 8
17 май 2025, 14:16
17 май 2025, 14:16
5db0512
Код
Авторство
О чём код?
use nom::{IResult, Parser, branch::alt, bytes::complete::tag, combinator::map}; use crate::parse_utils::token; #[derive(Debug)] pub enum UserParam { Ip, Phone, Other(String), } const PHONE: &[u8] = b"phone"; const IP: &[u8] = b"ip"; impl UserParam { pub fn parse(src: &[u8]) -> IResult<&[u8], Self> { map(alt((tag(PHONE), tag(IP), token)), |param| match param { PHONE => Self::Phone, IP => Self::Ip, _ => Self::Other(std::str::from_utf8(param).unwrap().to_owned()), }) .parse(src) } } impl std::fmt::Display for UserParam { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!( f, "{}", match self { UserParam::Ip => "ip", UserParam::Phone => "phone", UserParam::Other(other) => other.as_str(), } ) } }