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>,
},
}
Expand description
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.
ConsString
The result of concatenating two DynamicStrings.
Implementations§
Source§impl DynamicString
impl DynamicString
Sourcepub fn slice(&self, start: usize, length: usize) -> Self
pub fn slice(&self, start: usize, length: usize) -> Self
Extracts a section of a string and returns it as a new string, without modifying the original string.
Sourcepub fn append<T: Into<DynamicString>>(&self, other: T) -> Self
pub fn append<T: Into<DynamicString>>(&self, other: T) -> Self
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"));
Sourcepub fn index_of<T: Into<DynamicString>>(&self, pattern: T) -> Option<usize>
pub fn index_of<T: Into<DynamicString>>(&self, pattern: T) -> Option<usize>
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);
Sourcepub fn split<T: Into<DynamicString>>(
&self,
separator: T,
limit: Option<usize>,
) -> Vec<DynamicString>
pub fn split<T: Into<DynamicString>>( &self, separator: T, limit: Option<usize>, ) -> Vec<DynamicString>
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![""]);
Sourcepub fn starts_with<T: Into<DynamicString>>(&self, other: T) -> bool
pub fn starts_with<T: Into<DynamicString>>(&self, other: T) -> bool
Determines whether a string begins with the characters of a specified string, returning true or false as appropriate.
Source§impl DynamicString
impl DynamicString
pub fn new(data: &str) -> Self
Sourcepub fn has_one_byte_char(&self) -> bool
pub fn has_one_byte_char(&self) -> bool
Returns true if this string only contains one-byte characters.
Sourcepub fn iter(&self) -> DynamicStringIterator ⓘ
pub fn iter(&self) -> DynamicStringIterator ⓘ
Returns an iterator over the characters in this string.
Trait Implementations§
Source§impl<T: Into<DynamicString>> Add<T> for DynamicString
impl<T: Into<DynamicString>> Add<T> for DynamicString
Source§impl Clone for DynamicString
impl Clone for DynamicString
Source§fn clone(&self) -> DynamicString
fn clone(&self) -> DynamicString
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more