[][src]Enum dynstr::DynamicString

pub enum DynamicString {
    Empty,
    SingleOneByteChar(u8),
    SingleTwoByteChar(u16),
    SeqOneByteString(Arc<Vec<u8>>),
    SeqTwoByteString(Arc<Vec<u16>>),
    SlicedString {
        root: Box<DynamicString>,
        start: usize,
        length: usize,
    },
    ConsString {
        first: Box<DynamicString>,
        second: Box<DynamicString>,
    },
}

An immutable string representation with efficient memory management for heavy string manipulations.

Variants

Empty

Represents an empty string.

SingleOneByteChar(u8)

The string consists of a single one-byte (u8) character.

SingleTwoByteChar(u16)

The string consists of a single two-byte (u16) character.

SeqOneByteString(Arc<Vec<u8>>)

Sequence of one-byte characters (such as an ASCII text), the sequence must be non-empty.

SeqTwoByteString(Arc<Vec<u16>>)

Sequence of two-byte (utf-16) characters, the sequence must be non-empty.

SlicedString

A view over another DynamicString limited to the provided range.

Fields of SlicedString

root: Box<DynamicString>start: usizelength: usize
ConsString

The result of concatenating two DynamicStrings.

Fields of ConsString

first: Box<DynamicString>second: Box<DynamicString>

Implementations

impl DynamicString[src]

pub fn slice(&self, start: usize, length: usize) -> Self[src]

Extracts a section of a string and returns it as a new string, without modifying the original string.

pub fn append<T: Into<DynamicString>>(&self, other: T) -> Self[src]

Concatenate the current string with another string, returns the result.

use dynstr::DynamicString;
let str = DynamicString::new("hello");
assert_eq!(str.append(" world"), DynamicString::new("hello world"));

pub fn index_of<T: Into<DynamicString>>(&self, pattern: T) -> Option<usize>[src]

Return the index of the first occurrence of the specified value in the current string.

use dynstr::DynamicString;
let str = DynamicString::new("Hello world");
assert_eq!(str.index_of("world"), Some(6));
assert_eq!(str.index_of("world!"), None);

pub fn split<T: Into<DynamicString>>(
    &self,
    separator: T,
    limit: Option<usize>
) -> Vec<DynamicString>
[src]

Divides a String into an ordered list of substrings, puts these substrings into a vector, and returns the vector. The division is done by searching for a pattern; where the pattern is provided as the first parameter in the method's call.
This method tries to follow the JavaScript's String.split method in edge cases.

use dynstr::DynamicString;
let str = DynamicString::new("Hello world");
assert_eq!(DynamicString::new("Jack,Joe,John").split(",", None), vec!["Jack", "Joe", "John"]);
assert_eq!(DynamicString::new("Jack,Joe,John").split(",", Some(1)), vec!["Jack"]);
// edge cases:
assert!(DynamicString::new("").split("", None).is_empty());
assert_eq!(DynamicString::new("ABC").split("", None), vec!["A", "B", "C"]);
assert_eq!(DynamicString::new("").split("ABC", None), vec![""]);

pub fn starts_with<T: Into<DynamicString>>(&self, other: T) -> bool[src]

Determines whether a string begins with the characters of a specified string, returning true or false as appropriate.

impl DynamicString[src]

pub fn new(data: &str) -> Self[src]

pub fn empty() -> Self[src]

Returns a new empty string.

pub fn len(&self) -> usize[src]

Returns length of the string.

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

Returns true if this string only contains one-byte characters.

pub fn flatten(self) -> Self[src]

Flatten this DynamicString.

pub fn iter(&self) -> DynamicStringIterator

Notable traits for DynamicStringIterator

impl Iterator for DynamicStringIterator type Item = u16;
[src]

Returns an iterator over the characters in this string.

Trait Implementations

impl<T: Into<DynamicString>> Add<T> for DynamicString[src]

type Output = DynamicString

The resulting type after applying the + operator.

impl Clone for DynamicString[src]

impl Debug for DynamicString[src]

impl Display for DynamicString[src]

impl Eq for DynamicString[src]

impl<'_> From<&'_ DynamicString> for IndexedString[src]

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

impl From<DynamicString> for IndexedString[src]

impl From<DynamicString> for String[src]

impl Hash for DynamicString[src]

impl<'_> Into<DynamicString> for &'_ str[src]

impl IntoIterator for DynamicString[src]

type Item = u16

The type of the elements being iterated over.

type IntoIter = DynamicStringIterator

Which kind of iterator are we turning this into?

impl Ord for DynamicString[src]

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

impl PartialEq<DynamicString> for DynamicString[src]

impl PartialEq<str> for DynamicString[src]

impl PartialOrd<DynamicString> for DynamicString[src]

Auto Trait Implementations

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.