[−][src]Struct kserd::Kstr
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]
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]
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 Kstr<'a>
[src]
fn cmp(&self, other: &Kstr<'a>) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
1.21.0[src]
fn clamp(self, min: Self, max: Self) -> Self
[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]
fn partial_cmp(&self, other: &Kstr<'a>) -> Option<Ordering>
[src]
fn lt(&self, other: &Kstr<'a>) -> bool
[src]
fn le(&self, other: &Kstr<'a>) -> bool
[src]
fn gt(&self, other: &Kstr<'a>) -> bool
[src]
fn ge(&self, other: &Kstr<'a>) -> bool
[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]
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>,