[][src]Struct kserd::Kstr

pub struct Kstr<'a> {
    pub inner: Cow<'a, str>,
}

An owned or borrowed string.

Kstr provides a thin wrapper around Cow<str>. The smart pointer allows the string to be borrowed up until the point of mutation, at which point a clonse is made.

Fields

inner: Cow<'a, str>

Inner access to the underlying clone-on-write smart pointer.

Methods

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

pub const fn brwed(s: &'a str) -> Self[src]

A new borrowed string. Kstr has the same lifetime as the borrowed string.

pub const fn owned(s: String) -> Kstr<'static>[src]

A new owned string. Takes ownership of the string and has a 'static lifetime.

pub fn as_str(&self) -> &str[src]

Represent the string as a string slice.

Example

let kstr = Kstr::owned(String::from("Hello, world!"));
assert_eq!(kstr.as_str(), "Hello, world!");

pub fn to_mut(&mut self) -> &mut String[src]

Acquires a mutable reference to the owned string.

Clones the string if it not already owned.

Example

let mut kstr = Kstr::brwed("foo");
kstr.to_mut().make_ascii_uppercase();
assert_eq!(kstr, Kstr::brwed("FOO"));

pub fn into_owned(self) -> Kstr<'static>[src]

Makes the underlying string owned.

Clones the string if it is not already owned. This upgrades the lifetime to 'static.

Example

let kstr = Kstr::brwed("Hello, world!");
assert_eq!(kstr.to_owned(), Kstr::owned(String::from("Hello, world!")));

Trait Implementations

impl<'a> AsRef<str> for Kstr<'a>[src]

impl<'a> Clone for Kstr<'a>[src]

impl<'a> Debug for Kstr<'a>[src]

impl<'a> Deref for Kstr<'a>[src]

type Target = str

The resulting type after dereferencing.

impl<'a> Display for Kstr<'a>[src]

impl<'a> Eq for Kstr<'a>[src]

impl<'a> From<&'a str> for Kstr<'a>[src]

impl From<String> for Kstr<'static>[src]

impl<'a> Hash for Kstr<'a>[src]

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

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

impl<'a> PartialEq<str> for Kstr<'a>[src]

impl<'a> PartialOrd<Kstr<'a>> for Kstr<'a>[src]

impl<'a> StructuralEq for Kstr<'a>[src]

impl<'a> StructuralPartialEq for Kstr<'a>[src]

Auto Trait Implementations

impl<'a> RefUnwindSafe for Kstr<'a>

impl<'a> Send for Kstr<'a>

impl<'a> Sync for Kstr<'a>

impl<'a> Unpin for Kstr<'a>

impl<'a> UnwindSafe for Kstr<'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.