Struct basic_text::TextString [−][src]
#[repr(transparent)]pub struct TextString(_);Expand description
A Basic Text encoded, growable string.
This is an owning string similar to String, but ensures the contents
are Basic Text rather than just UTF-8. It’s accompanied by a borrowing
TextStr, which plays an analogous role to str.
Examples
You can create a TextString from a literal text string with
TextString::from:
use basic_text::{text, TextString};
let hello = TextString::from(text!("Hello, world!"));You can append a &TextStr with the push_text method:
use basic_text::{text, TextString};
let mut hello = TextString::from(text!("Hello, "));
hello.push_text(text!("world!"));If you have a String containing a Basic Text string, you can create a
TextString from it with the from_text method:
use basic_text::{text, TextString};
// a `String`
let sparkle_heart = "💖".to_owned();
// We know this string is valid, so we'll use `unwrap()`.
let sparkle_heart = TextString::from_text(sparkle_heart).unwrap();
assert_eq!(text!("💖"), &sparkle_heart);If you have a vector of Basic Text bytes, you can create a String from it
with the from_text_vec method:
use basic_text::{text, TextString};
// some bytes, in a vector
let sparkle_heart = vec![240, 159, 146, 150];
// We know these bytes are valid, so we'll use `unwrap()`.
let sparkle_heart = TextString::from_text_vec(sparkle_heart).unwrap();
assert_eq!(text!("💖"), &sparkle_heart);Implementations
Creates a new empty TextString with a particular capacity.
Converts a vector of bytes to a TextString.
Converts a String to a TextString.
Converts a slice of bytes to Basic Text, including invalid characters.
Converts a string to Basic Text, including invalid characters.
Converts a vector of bytes to a TextString without checking that the
string contains valid Basic Text.
Safety
This function is unsafe because it does not check that the bytes passed
to it are valid Basic Text. If this constraint is violated, undefined
behavior results, as the rest of this crate assumes that &TextStrs
are valid Basic Text.
Converts a String to a TextString without checking that the string
contains valid Basic Text.
Safety
This function is unsafe because it does not check that the bytes passed
to it are valid Basic Text. If this constraint is violated, undefined
behavior results, as the rest of this crate assumes that &TextStrs
are valid Basic Text.
Converts a TextString into a String.
Converts a String into a byte vector.
Extracts a Basic Text string slice containing the entire TextString.
Converts a TextString into a mutable Basic Text string slice.
Appends a given string slice onto the end of this TextString.
But wait, isn’t NFC closed under concatenation? This is true, but Basic Text has additional restrictions, including that strings start with non-combining codepoints, so it is closed under concatenation.
Ensures that this TextString’s capacity is at least additional
bytes larger than its length.
Ensures that this TextString’s capacity is additional bytes larger
than its length.
Tries to reserve capacity for at least additional more elements to
be inserted in the given TextString.
Tries to reserves the minimum capacity for exactly additional more
elements to be inserted in the given TextString.
Shrinks the capacity of this TextString to match its length.
Shrinks the capacity of this String with a lower bound.
Returns a byte slice of this TextString’s contents.
Returns a mutable reference to the contents of this TextString.
Safety
This function is unsafe because it does not check that the bytes passed
to it are valid Basic Text. If this constraint is violated, it may
cause memory unsafety issues with future users of the String, as the
rest of this crate assumes that TextStrings are valid Basic Text.
Returns a mutable reference to the contents of this TextString.
Safety
This function is unsafe because it does not check that the bytes passed
to it are valid Basic Text. If this constraint is violated, it may
cause memory unsafety issues with future users of the String, as the
rest of this crate assumes that TextStrings are valid Basic Text.
Returns the length of this TextString, in bytes, not chars or
graphemes.
Returns true if this TextString has a length of zero, and false
otherwise.
Converts this TextString into a Box<str>.
Converts this TextString into a Box<TextStr>.
Methods from Deref<Target = TextStr>
Converts a text string slice to a byte slice.
Converts a mutable text string slice to a mutable byte slice.
Safety
The caller must ensure that the content of the slice is valid
Basic Text before the borrow ends and the underlying TextStr is used.
Use of a TextStr whose contents are not valid Basic Text is undefined
behavior.
Converts a mutable text string slice to a raw pointer.
Divide one text string slice into two at an index.
Divide one mutable text string slice into two at an index.
Returns an iterator over the chars of a text string slice, and their
positions.
An iterator over the lines of a text string, as text string slices.
TODO: There should be a TextLines which yields &TextStrs.
Returns an iterator of u16 over the string encoded as Basic Text.
Returns true if the given pattern matches a sub-slice of this
text string slice.
Returns false if it does not.
Returns true if the given pattern matches a prefix of this
text string slice.
Returns false if it does not.
Returns true if the given pattern matches a suffix of this
text string slice.
Returns false if it does not.
Returns the byte index of the first character of this text string slice that matches the pattern.
Returns None if the pattern doesn’t match.
Returns the byte index for the first character of the rightmost match of the pattern in this text string slice.
Returns None if the pattern doesn’t match.
An iterator over the disjoint matches of a pattern within the given text string slice.
An iterator over the disjoint matches of a pattern within this text string slice, yielded in reverse order.
TODO: There should be a TextRMatches which yields &TextStrs.
An iterator over the disjoint matches of a pattern within this text string slice as well as the index that the match starts at.
TODO: There should be a TextMatchIndices which yields &TextStrs.
pub fn rmatch_indices<'a, P>(&'a self, pat: P) -> RMatchIndices<'a, P> where
P: Pattern<'a>,
<P as Pattern<'a>>::Searcher: ReverseSearcher<'a>,
pub fn rmatch_indices<'a, P>(&'a self, pat: P) -> RMatchIndices<'a, P> where
P: Pattern<'a>,
<P as Pattern<'a>>::Searcher: ReverseSearcher<'a>,
An iterator over the disjoint matches of a pattern within self,
yielded in reverse order along with the index of the match.
TODO: There should be a TextRMatchIndices which yields &TextStrs.
Returns a text string slice with leading and trailing whitespace removed.
Returns a text string slice with leading whitespace removed.
Parses this text string slice into another type.
Checks if all characters in this text string are within the ASCII range.
Checks that two text strings are an ASCII case-insensitive match.
Creates a new TextString by repeating a string n times.
Return an iterator that escapes each char in self with
char::escape_debug.
Return an iterator that escapes each char in self with
char::escape_default.
Return an iterator that escapes each char in self with
char::escape_unicode.
Trait Implementations
Performs the += operation. Read more
Performs the conversion.
Mutably borrows from an owned value. Read more
Extends a collection with the contents of an iterator. Read more
extend_one)Extends a collection with exactly one element.
extend_one)Reserves capacity in a collection for the given number of additional elements. Read more
Extends a collection with the contents of an iterator. Read more
extend_one)Extends a collection with exactly one element.
extend_one)Reserves capacity in a collection for the given number of additional elements. Read more
Extends a collection with the contents of an iterator. Read more
extend_one)Extends a collection with exactly one element.
extend_one)Reserves capacity in a collection for the given number of additional elements. Read more
Performs the conversion.
This method tests for self and other values to be equal, and is used
by ==. Read more
This method tests for !=.
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
Auto Trait Implementations
impl RefUnwindSafe for TextString
impl Send for TextString
impl Sync for TextString
impl Unpin for TextString
impl UnwindSafe for TextString
Blanket Implementations
Mutably borrows from an owned value. Read more