Update parse_with_server_name's id bounds
… from `Into<Cow<'a, str>>` to `AsRef<str> + Into<String>`
This commit is contained in:
parent
50cc35f1fe
commit
acb02f96bc
@ -63,22 +63,23 @@ impl UserId {
|
|||||||
/// user ID or just the localpart. It only supports a valid user ID or a valid user ID
|
/// user ID or just the localpart. It only supports a valid user ID or a valid user ID
|
||||||
/// localpart, not the localpart plus the `@` prefix, or the localpart plus server name without
|
/// localpart, not the localpart plus the `@` prefix, or the localpart plus server name without
|
||||||
/// the `@` prefix.
|
/// the `@` prefix.
|
||||||
pub fn parse_with_server_name<'a>(
|
pub fn parse_with_server_name(
|
||||||
id: impl Into<Cow<'a, str>>,
|
id: impl AsRef<str> + Into<String>,
|
||||||
server_name: &str,
|
server_name: &str,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let id = id.into();
|
let id_str = id.as_ref();
|
||||||
if id.starts_with('@') {
|
|
||||||
Self::try_from(id)
|
if id_str.starts_with('@') {
|
||||||
|
Self::try_from(id.into())
|
||||||
} else {
|
} else {
|
||||||
let is_fully_conforming = localpart_is_fully_comforming(&id)?;
|
let is_fully_conforming = localpart_is_fully_comforming(id_str)?;
|
||||||
if !is_valid_server_name(server_name) {
|
if !is_valid_server_name(server_name) {
|
||||||
return Err(Error::InvalidServerName);
|
return Err(Error::InvalidServerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
full_id: format!("@{}:{}", id, server_name),
|
full_id: format!("@{}:{}", id_str, server_name),
|
||||||
colon_idx: NonZeroU8::new(id.len() as u8 + 1).unwrap(),
|
colon_idx: NonZeroU8::new(id_str.len() as u8 + 1).unwrap(),
|
||||||
is_historical: !is_fully_conforming,
|
is_historical: !is_fully_conforming,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user