Struct basic_text::TextSubstring [−][src]
#[repr(transparent)]pub struct TextSubstring(_);Expand description
A substring of a Basic Text string or stream.
This does not enforce the Basic Text requirements on the beginning or end of a stream, so it can represent substrings of Basic Text.
This is an owning string similar to TextString, but doesn’t enforce the
starting and ending requirements, so it can represent substrings. It’s
accompanied by a borrowing TextSubstr, which plays an analogous role to
TextStr.
Examples
You can create a TextSubstring from a literal text string with
TextSubstring::from:
use basic_text::{text_substr, TextSubstring};
let hello = TextSubstring::from(text_substr!("Hello, world!"));If you have a String containing a Basic Text string, you can create a
TextSubstring from it with the from_text method:
use basic_text::{text_substr, TextSubstring};
// a `String`
let sparkle_heart = "💖".to_owned();
// We know this string is valid, so we'll use `unwrap()`.
let sparkle_heart = TextSubstring::from_text(sparkle_heart).unwrap();
assert_eq!(text_substr!("💖"), &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_substr, TextSubstring};
// 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 = TextSubstring::from_text_vec(sparkle_heart).unwrap();
assert_eq!(text_substr!("💖"), &sparkle_heart);Implementations
Creates a new empty TextSubstring with a particular capacity.
Converts a vector of bytes to a TextSubstring.
Converts a String to a TextSubstring.
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 TextSubstring 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 &TextSubstrs
are valid Basic Text.
Converts a String to a TextSubstring 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 &TextSubstrs
are valid Basic Text.
Converts a TextSubstring into a String.
Converts a String into a byte vector.
Extracts a Basic Text string slice containing the entire
TextSubstring.
Converts a TextSubstring into a mutable Basic Text substring slice.
Ensures that this TextSubstring’s capacity is at least additional
bytes larger than its length.
Ensures that this TextSubstring’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 TextSubstring.
Tries to reserves the minimum capacity for exactly additional more
elements to be inserted in the given TextSubstring.
Shrinks the capacity of this TextSubstring to match its length.
Shrinks the capacity of this String with a lower bound.
Returns a byte slice of this TextSubstring’s contents.
Returns a mutable reference to the contents of this TextSubstring.
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 TextSubstrings are valid Basic Text.
Returns a mutable reference to the contents of this TextSubstring.
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 TextSubstrings are valid Basic Text.
Returns the length of this TextSubstring, in bytes, not chars or
graphemes.
Returns true if this TextSubstring has a length of zero, and
false otherwise.
Converts this TextSubstring into a Box<str>.
Converts this TextSubstring into a Box<TextSubstr>.
Methods from Deref<Target = TextSubstr>
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 TextSubstr is
used.
Use of a TextSubstr 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 &TextSubstrs.
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.
TODO: There should be a TextMatches which yields &TextSubstrs.
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 &TextSubstrs.
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 &TextSubstrs.
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
&TextSubstrs.
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 TextSubstring 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 conversion.
Performs the conversion.
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
type Target = TextSubstr
type Target = TextSubstr
The resulting type after dereferencing.
Performs the conversion.
Performs the conversion.
Performs the conversion.
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 TextSubstring
impl Send for TextSubstring
impl Sync for TextSubstring
impl Unpin for TextSubstring
impl UnwindSafe for TextSubstring
Blanket Implementations
Mutably borrows from an owned value. Read more