[−][src]Struct mownstr::MownStr
"Maybe own str":Option
either a borrowed reference to a str
or an own Box<str>
.
It does not try to be mutable, nor generic,
which makes it lighter than, for example, Cow<str>
.
Panic
The drawback is that MownStr
does not support strings with a length > usize::MAX/2
.
Trying to convert such a large string to a MownStr
will panic.
Methods
impl<'a> MownStr<'a>
[src]
impl<'a> MownStr<'a>
[src]
pub fn to<T>(self) -> T where
T: From<&'a str> + From<Box<str>>,
[src]
T: From<&'a str> + From<Box<str>>,
Convert this MownStr
to ant type T
that can be created from either a &str
or a Box<str>
.
This can not be implemented with the From
trait,
because this would conflict with From<MownStr<'a>>
.
Usage
let ms = MownStr::from("hello world"); let rc = ms.to::<Rc<str>>(); let o1 = Some(MownStr::from("hi there")); let o2 = o1.map(MownStr::to::<Rc<str>>);
Trait Implementations
impl<'a> AsRef<str> for MownStr<'a>
[src]
impl<'a> Borrow<str> for MownStr<'a>
[src]
impl<'a> Clone for MownStr<'a>
[src]
impl<'a> Debug for MownStr<'a>
[src]
impl<'a> Deref for MownStr<'a>
[src]
impl<'a> Display for MownStr<'a>
[src]
impl<'a> Drop for MownStr<'a>
[src]
impl<'a> Eq for MownStr<'a>
[src]
impl<'a> From<&'a str> for MownStr<'a>
[src]
impl<'a> From<Box<str>> for MownStr<'a>
[src]
impl<'a> From<Cow<'a, str>> for MownStr<'a>
[src]
impl<'a> From<MownStr<'a>> for Box<str>
[src]
impl<'a> From<MownStr<'a>> for String
[src]
impl<'a> From<MownStr<'a>> for Cow<'a, str>
[src]
impl<'a> From<String> for MownStr<'a>
[src]
impl<'a> Hash for MownStr<'a>
[src]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<'a> Ord for MownStr<'a>
[src]
fn cmp(&self, other: &MownStr<'a>) -> Ordering
[src]
#[must_use]fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self
[src]
impl<'a> PartialEq<&'a str> for MownStr<'a>
[src]
impl<'a> PartialEq<MownStr<'a>> for MownStr<'a>
[src]
fn eq(&self, other: &MownStr<'a>) -> bool
[src]
#[must_use]fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<'a> PartialEq<MownStr<'a>> for &'a str
[src]
fn eq(&self, other: &MownStr<'a>) -> bool
[src]
#[must_use]fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<'a> PartialOrd<&'a str> for MownStr<'a>
[src]
fn partial_cmp(&self, other: &&'a str) -> Option<Ordering>
[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<'a> PartialOrd<MownStr<'a>> for MownStr<'a>
[src]
fn partial_cmp(&self, other: &MownStr<'a>) -> Option<Ordering>
[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<'a> PartialOrd<MownStr<'a>> for &'a str
[src]
Auto Trait Implementations
impl<'a> RefUnwindSafe for MownStr<'a>
impl<'a> Send for MownStr<'a>
impl<'a> Sync for MownStr<'a>
impl<'a> Unpin for MownStr<'a>
impl<'a> UnwindSafe for MownStr<'a>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,