#[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.

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 UTF-8 string slice containing the entire TextSubstring.

Extracts a Basic Text string slice containing the entire TextSubstring.

Converts a TextSubstring into a mutable Basic Text substring slice.

Returns this TextSubstring’s capacity, in bytes.

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.

Truncates this String, removing all contents.

Converts this TextSubstring into a Box<str>.

Converts this TextSubstring into a Box<TextSubstr>.

Methods from Deref<Target = TextSubstr>

Returns the length of self.

Returns true if self has a length of zero bytes.

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 text string slice to a raw pointer.

Converts a mutable text string slice to a raw pointer.

Extracts a UTF-8 string slice containing the entire TextSubstr.

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.

Returns an iterator over the chars of a text string slice, and their positions.

An iterator over the bytes of a text string slice.

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.

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.

Returns a text string slice with trailing 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

Converts this type into a mutable reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
The resulting type after dereferencing.
Dereferences the value.
Mutably dereferences the value.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
The returned type after indexing.
Performs the indexing (container[index]) operation. Read more
The returned type after indexing.
Performs the indexing (container[index]) operation. Read more
The returned type after indexing.
Performs the indexing (container[index]) operation. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
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
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.