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) -> Self
pub fn new(raw: &str) -> Self
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§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<T> CompatExt for T
impl<T> CompatExt for T
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<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
source§fn consume_handle(handle: Handle) -> Arc<T>
fn consume_handle(handle: Handle) -> Arc<T>
Arc<>
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,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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