Jonas Platte 22ec1710b5
Update ruma-identifiers validation logic
* Allow empty localparts
* Simplify some code
2020-09-21 22:34:56 +02:00

17 lines
351 B
Rust

use std::num::NonZeroU8;
use crate::{parse_id, Error};
pub fn validate(s: &str) -> Result<Option<NonZeroU8>, Error> {
Ok(match s.contains(':') {
true => Some(parse_id(s, &['$'])?),
false => {
if !s.starts_with('$') {
return Err(Error::MissingSigil);
}
None
}
})
}