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.

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

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.

Returns this TextString’s capacity, in bytes.

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.

Truncates this String, removing all contents.

Converts this TextString into a Box<str>.

Converts this TextString into a Box<TextStr>.

Methods from Deref<Target = TextStr>

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 TextStr is used.

Use of a TextStr 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 TextStr.

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 &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.

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.

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 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

The resulting type after applying the + operator.

Performs the + operation. Read more

Performs the += operation. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

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.

Extends a collection with the contents of an iterator. Read more

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

🔬 This is a nightly-only experimental API. (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

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

🔬 This is a nightly-only experimental API. (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

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

🔬 This is a nightly-only experimental API. (extend_one)

Reserves capacity in a collection for the given number of additional elements. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

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 !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

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

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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.