[][src]Struct pstr::MowStr

pub struct MowStr(_);

Mutable on Write Interning String

It will be auto switch to mutable when do modify operate

Can call .intern() to save into intern pool

Example

let mut s = MowStr::new("hello");
assert!(s.is_interned());

s.push_str(" ");
assert!(s.is_mutable());

s.mutdown().push_str("world");
assert_eq!(s, "hello world");

s.intern();
assert!(s.is_interned());

Implementations

impl MowStr[src]

pub fn new(s: impl AsRef<str>) -> Self[src]

Create a MowStr from str slice

Example

let s = MowStr::new("hello world");

pub fn new_mut(s: impl Into<String>) -> Self[src]

Create a MowStr from str slice with mutable

Example

let s = MowStr::new_mut("hello world");
assert!(s.is_mutable());

pub fn mut_empty() -> Self[src]

Create a new empty MowStr with mutable

Example

let s = MowStr::mut_empty();
assert!(s.is_mutable());

pub fn mut_with_capacity(capacity: usize) -> Self[src]

Create a new empty MowStr with a particular capacity and mutable

pub fn from_string(s: String) -> Self[src]

Create a MowStr from String

pub fn from_string_mut(s: String) -> Self[src]

Create a MowStr from String with mutable

pub fn from_boxed(s: Box<str>) -> Self[src]

Create a MowStr from Box<str>

pub fn from_arc(s: Arc<str>) -> Self[src]

Create a MowStr from Arc<str>

pub fn from_rc(s: Rc<str>) -> Self[src]

Create a MowStr from Rc<str>

pub fn from_istr(s: IStr) -> Self[src]

Create a MowStr from IStr

pub fn from_to_arc<S: AsRef<str>>(
    s: S,
    to_arc: impl FnOnce(S) -> Arc<str>
) -> Self
[src]

Create a MowStr from custom fn

impl MowStr[src]

pub fn intern(&mut self)[src]

Save the current state to the intern pool
Do nothing if already in the pool

pub fn to_mut(&mut self)[src]

Get a mutable clone of the string on the pool
Do nothing if already mutable

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

Switch to mutable and return a mutable reference

pub fn to_mut_by(&mut self, f: impl FnOnce(&mut IStr) -> String)[src]

Do nothing if already mutable

pub fn swap_mut(&mut self, s: String) -> Option<String>[src]

Swap internal String
Return None if self is interned

pub fn try_swap_mut(&mut self, s: String) -> Option<String>[src]

Swap internal String when self is mutable
Do nothing if self is interned
Return None if self is interned

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

Check if it is in intern pool

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

Check if it is mutable

pub fn try_istr(&self) -> Option<&IStr>[src]

Try get IStr

pub fn try_string(&self) -> Option<&String>[src]

Try get String

pub fn into_istr(&self) -> IStr[src]

Make a IStr

impl MowStr[src]

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

Get &str

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

Get &mut str

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

Get &mut String

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

Extracts a string slice containing the entire MowStr

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

Switch to mutable and returns a mutable string slice.

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

Switch to mutable and returns a mutable String reference

pub unsafe fn as_mut_vec(&mut self) -> &mut Vec<u8>[src]

Switch to mutable and returns a mutable Vec<u8> reference

pub fn into_string(self) -> String[src]

Convert to String

pub fn into_boxed_str(self) -> Box<str>[src]

Convert to Box<str>

impl MowStr[src]

pub fn push_str(&mut self, string: impl AsRef<str>)[src]

Appends a given string slice onto the end of this MowStr

pub fn reserve(&mut self, additional: usize)[src]

Ensures that this MowStr's capacity is at least additional bytes larger than its length.

The capacity may be increased by more than additional bytes if it chooses, to prevent frequent reallocations.

If you do not want this "at least" behavior, see the reserve_exact method.

Panics

Panics if the new capacity overflows usize.

pub fn reserve_exact(&mut self, additional: usize)[src]

Ensures that this MowStr's capacity is additional bytes larger than its length.

Consider using the reserve method unless you absolutely know better than the allocator.

Panics

Panics if the new capacity overflows usize.

pub fn shrink_to_fit(&mut self)[src]

Shrinks the capacity of this MowStr to match its length.

pub fn push(&mut self, ch: char)[src]

Appends the given char to the end of this MowStr.

pub fn truncate(&mut self, new_len: usize)[src]

Shortens this MowStr to the specified length.

If new_len is greater than the string's current length, this has no effect.

Note that this method has no effect on the allocated capacity of the string

Panics

Panics if new_len does not lie on a char boundary.

pub fn pop(&mut self) -> Option<char>[src]

Removes the last character from the string buffer and returns it.

Returns None if this MowStr is empty.

pub fn remove(&mut self, idx: usize) -> char[src]

Removes a char from this MowStr at a byte position and returns it.

This is an O(n) operation, as it requires copying every element in the buffer.

Panics

Panics if idx is larger than or equal to the MowStr's length, or if it does not lie on a char boundary.

pub fn retain<F: FnMut(char) -> bool>(&mut self, f: F)[src]

Retains only the characters specified by the predicate.

In other words, remove all characters c such that f(c) returns false. This method operates in place, visiting each character exactly once in the original order, and preserves the order of the retained characters.

pub fn insert(&mut self, idx: usize, ch: char)[src]

Inserts a character into this MowStr at a byte position.

This is an O(n) operation as it requires copying every element in the buffer.

Panics

Panics if idx is larger than the MowStr's length, or if it does not lie on a char boundary.

pub fn insert_str(&mut self, idx: usize, string: &str)[src]

Inserts a string slice into this MowStr at a byte position.

This is an O(n) operation as it requires copying every element in the buffer.

Panics

Panics if idx is larger than the MowStr's length, or if it does not lie on a char boundary.

pub fn split_off(&mut self, at: usize) -> MowStr[src]

Splits the string into two at the given index.

Returns a newly allocated MowStr. self contains bytes [0, at), and the returned MowStr contains bytes [at, len). at must be on the boundary of a UTF-8 code point.

Note that the capacity of self does not change.

Panics

Panics if at is not on a UTF-8 code point boundary, or if it is beyond the last code point of the string.

pub fn clear(&mut self)[src]

Truncates this MowStr, removing all contents.

While this means the MowStr will have a length of zero, it does not touch its capacity.

pub fn drain<R: RangeBounds<usize>>(&mut self, range: R) -> Drain<'_>[src]

Creates a draining iterator that removes the specified range in the MowStr and yields the removed chars.

Note: The element range is removed even if the iterator is not consumed until the end.

Panics

Panics if the starting point or end point do not lie on a char boundary, or if they're out of bounds.

pub fn replace_range<R: RangeBounds<usize>>(
    &mut self,
    range: R,
    replace_with: &str
)
[src]

Removes the specified range in the string, and replaces it with the given string. The given string doesn't need to be the same length as the range.

Panics

Panics if the starting point or end point do not lie on a char boundary, or if they're out of bounds.

Trait Implementations

impl<'_> Add<&'_ str> for MowStr[src]

type Output = MowStr

The resulting type after applying the + operator.

impl<'_> AddAssign<&'_ str> for MowStr[src]

impl AsMut<String> for MowStr[src]

impl AsMut<str> for MowStr[src]

impl AsRef<[u8]> for MowStr[src]

impl AsRef<OsStr> for MowStr[src]

impl AsRef<Path> for MowStr[src]

impl AsRef<str> for MowStr[src]

impl Borrow<str> for MowStr[src]

impl BorrowMut<str> for MowStr[src]

impl Clone for MowStr[src]

impl Debug for MowStr[src]

impl Deref for MowStr[src]

type Target = str

The resulting type after dereferencing.

impl DerefMut for MowStr[src]

impl Eq for MowStr[src]

impl<'a> Extend<&'a char> for MowStr[src]

impl<'a> Extend<&'a str> for MowStr[src]

impl Extend<Box<str>> for MowStr[src]

impl<'a> Extend<Cow<'a, str>> for MowStr[src]

impl Extend<IStr> for MowStr[src]

impl Extend<MowStr> for MowStr[src]

impl Extend<String> for MowStr[src]

impl<'_> From<&'_ String> for MowStr[src]

impl<'_> From<&'_ mut str> for MowStr[src]

impl<'_> From<&'_ str> for MowStr[src]

impl<'a> From<&'a MowStr> for Cow<'a, str>[src]

impl From<Arc<str>> for MowStr[src]

impl From<Box<str>> for MowStr[src]

impl<'a> From<Cow<'a, str>> for MowStr[src]

impl From<IStr> for MowStr[src]

impl From<MowStr> for String[src]

impl From<MowStr> for Box<str>[src]

impl From<MowStr> for IStr[src]

impl From<MowStr> for Vec<u8>[src]

impl From<MowStr> for Arc<str>[src]

impl From<MowStr> for Rc<str>[src]

impl<'a> From<MowStr> for Cow<'a, str>[src]

impl From<MowStr> for Box<dyn Error>[src]

impl From<MowStr> for Box<dyn Error + Send + Sync>[src]

impl From<MowStr> for OsString[src]

impl From<MowStr> for PathBuf[src]

impl From<Rc<str>> for MowStr[src]

impl From<String> for MowStr[src]

impl From<char> for MowStr[src]

impl<'a> FromIterator<&'a char> for MowStr[src]

impl<'a> FromIterator<&'a str> for MowStr[src]

impl FromIterator<Box<str>> for MowStr[src]

impl<'a> FromIterator<Cow<'a, str>> for MowStr[src]

impl FromIterator<String> for MowStr[src]

impl FromIterator<char> for MowStr[src]

impl FromStr for MowStr[src]

type Err = ParseError

The associated error which can be returned from parsing.

impl Hash for MowStr[src]

impl<I: SliceIndex<str>> Index<I> for MowStr[src]

type Output = <I as SliceIndex<str>>::Output

The returned type after indexing.

impl<I: SliceIndex<str>> IndexMut<I> for MowStr[src]

impl Interning for MowStr[src]

type Outern = MowStr

impl Muterning for MowStr[src]

type Outern = MowStr

impl Ord for MowStr[src]

impl<'_> PartialEq<&'_ OsStr> for MowStr[src]

impl<'_> PartialEq<&'_ str> for MowStr[src]

impl PartialEq<MowStr> for MowStr[src]

impl PartialEq<OsStr> for MowStr[src]

impl PartialEq<OsString> for MowStr[src]

impl PartialEq<String> for MowStr[src]

impl PartialEq<str> for MowStr[src]

impl PartialOrd<MowStr> for MowStr[src]

impl StructuralEq for MowStr[src]

impl StructuralPartialEq for MowStr[src]

impl ToSocketAddrs for MowStr[src]

type Iter = <str as ToSocketAddrs>::Iter

Returned iterator over socket addresses which this type may correspond to. Read more

impl ToString for MowStr[src]

impl Write for MowStr[src]

Auto Trait Implementations

impl RefUnwindSafe for MowStr

impl Send for MowStr

impl Sync for MowStr

impl Unpin for MowStr

impl UnwindSafe for MowStr

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.