[][src]Struct mownstr::MownStr

pub struct MownStr<'a>(_);

"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]

pub fn is_borrowed(&self) -> bool[src]

pub fn is_owned(&self) -> bool[src]

impl<'a> MownStr<'a>[src]

pub fn to<T>(self) -> T where
    T: From<&'a str> + From<Box<str>>, 
[src]

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]

type Target = str

The resulting type after dereferencing.

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]

impl<'a> Ord for MownStr<'a>[src]

impl<'a> PartialEq<&'a str> for MownStr<'a>[src]

impl<'a> PartialEq<MownStr<'a>> for MownStr<'a>[src]

impl<'a> PartialEq<MownStr<'a>> for &'a str[src]

impl<'a> PartialOrd<&'a str> for MownStr<'a>[src]

impl<'a> PartialOrd<MownStr<'a>> for MownStr<'a>[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]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.