pub struct DisplayName { /* private fields */ }
Expand description
A high-level wrapper for strings representing display names.
This wrapper provides attempts to determine whether a display name contains characters that could make it ambiguous or easily confused with similar names.
§Examples
use matrix_sdk_base::deserialized_responses::DisplayName;
let display_name = DisplayName::new("𝒮𝒶𝒽𝒶𝓈𝓇𝒶𝒽𝓁𝒶");
// The normalized and sanitized string will be returned by DisplayName.as_normalized_str().
assert_eq!(display_name.as_normalized_str(), Some("sahasrahla"));
let display_name = DisplayName::new("@alice:localhost");
// The display name looks like an MXID, which makes it ambiguous.
assert!(display_name.is_inherently_ambiguous());
Implementations§
Source§impl DisplayName
impl DisplayName
Sourcepub fn new(raw: &str) -> DisplayName
pub fn new(raw: &str) -> DisplayName
Creates a new DisplayName
from the given raw string.
The raw display name is transformed into a Unicode-normalized form, with common confusable characters removed to reduce ambiguity.
Note: If removing confusable characters fails,
DisplayName::is_inherently_ambiguous
will return true
, and
DisplayName::as_normalized_str()
will return `None.
Sourcepub fn is_inherently_ambiguous(&self) -> bool
pub fn is_inherently_ambiguous(&self) -> bool
Is this display name considered to be ambiguous?
If the display name has cancer (i.e. fails normalisation or has a different normalised form) or looks like an MXID, then it’s ambiguous.
Sourcepub fn as_raw_str(&self) -> &str
pub fn as_raw_str(&self) -> &str
Returns the underlying raw and and unsanitized string of this
DisplayName
.
Sourcepub fn as_normalized_str(&self) -> Option<&str>
pub fn as_normalized_str(&self) -> Option<&str>
Returns the underlying normalized and and sanitized string of this
DisplayName
.
Returns None
if normalization failed during construction of this
DisplayName
.
Trait Implementations§
Source§impl Clone for DisplayName
impl Clone for DisplayName
Source§fn clone(&self) -> DisplayName
fn clone(&self) -> DisplayName
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for DisplayName
impl Debug for DisplayName
Source§impl Hash for DisplayName
impl Hash for DisplayName
Source§impl PartialEq for DisplayName
impl PartialEq for DisplayName
impl Eq for DisplayName
Auto Trait Implementations§
impl Freeze for DisplayName
impl RefUnwindSafe for DisplayName
impl Send for DisplayName
impl Sync for DisplayName
impl Unpin for DisplayName
impl UnwindSafe for DisplayName
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more