Struct roblox::data_type::string::String[][src]

pub struct String {}
Expand description

A UTF-8–encoded, growable string.

The String type is the most common string type that has ownership over the contents of the string. It has a close relationship with its borrowed counterpart, the primitive str.

This type is equivalent to the normal Rust string type, but is not actually functional, and also implements the Copy trait.

Implementations

Creates a new empty String.

This will compile into an empty string literal.

Creates a new empty String with a particular capacity.

Note that Strings in Luau do not have a capacity in the same way as Rust, so this is equivalent to new() and is only present for compatibility with the normal Rust String type.

Converts a vector of bytes to a String.

Converts a slice of bytes to a string, including invalid characters.

Decode a UTF-16–encoded vector v into a String, returning Err if v contains any invalid data.

Decode a UTF-16–encoded slice v into a String, replacing invalid data with the replacement character (U+FFFD).

Unlike from_utf8_lossy which returns a Cow<'a, str>, from_utf16_lossy returns a String since the UTF-16 to UTF-8 conversion requires a memory allocation.

Converts a vector of bytes to a String without checking that the string contains valid UTF-8.

See the safe version, from_utf8, for more details.

Safety

This function is unsafe because it does not check that the bytes passed to it are valid UTF-8. If this constraint is violated, it may cause memory unsafety issues with future users of the String, as the rest of the standard library assumes that Strings are valid UTF-8.

Converts a String into a byte vector.

This consumes the String, so we do not need to copy its contents.

Extracts a string slice containing the entire String.

Converts a String into a mutable string slice.

Appends a given string slice onto the end of this String.

Returns this String’s capacity, in bytes.

Ensures that this String’s capacity is at least additional bytes larger than its length.

This function actually does nothing in Luau, and will not be transpiled.

Ensures that this String’s capacity is additional bytes larger than its length.

This function does nothing in Luau and will not be transpiled.

Shrinks the capacity of this String to match its length.

This function does nothing in Luau and will not be transpiled.

Appends the given char to the end of this String.

Returns a byte slice of this String’s contents.

The inverse of this method is from_utf8.

Shortens this String to the specified length.

If new_len is greater than the string’s current length, this has no effect.

Panics

Panics if new_len does not lie on a char boundary.

Removes the last character from the string buffer and returns it.

Returns None if this String is empty.

Removes a char from this String at a byte position and returns it.

Panics

Panics if idx is larger than or equal to the String’s length, or if it does not lie on a char boundary.

Retains only the characters specified by the predicate.

In other words, remove all characters c such that f(c) returns false. This method operates in place, visiting each character exactly once in the original order, and preserves the order of the retained characters.

Inserts a character into this String at a byte position.

Panics

Panics if idx is larger than the String’s length, or if it does not lie on a char boundary.

Inserts a string slice into this String at a byte position.

Panics

Panics if idx is larger than the String’s length, or if it does not lie on a char boundary.

Returns a mutable reference to the contents of this String.

Returns the length of this String, in bytes, not chars or graphemes. In other words, it may not be what a human considers the length of the string.

Returns true if this String has a length of zero, and false otherwise.

Splits the string into two at the given byte index.

Returns a newly allocated String. self contains bytes [0, at), and the returned String contains bytes [at, len). at must be on the boundary of a UTF-8 code point.

Panics

Panics if at is not on a UTF-8 code point boundary, or if it is beyond the last code point of the string.

Truncates this String, removing all contents.

While this means the String will have a length of zero, it does not touch its capacity.

Creates a draining iterator that removes the specified range in the String and yields the removed chars.

Note: The element range is removed even if the iterator is not consumed until the end.

Panics

Panics if the starting point or end point do not lie on a char boundary, or if they’re out of bounds.

Removes the specified range in the string, and replaces it with the given string. The given string doesn’t need to be the same length as the range.

Panics

Panics if the starting point or end point do not lie on a char boundary, or if they’re out of bounds.

Converts this String into a Box<str>.

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.

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.

Implements display for the String type.

This would never run in normal Rust, so anything can be written out.

Formats the value using the given formatter. Read more

Implement from for &str, but don’t do anything other than returning an empty instance of itself.

Performs the conversion.

Convert from Rust’s String type to this String type automatically.

Performs the conversion.

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

This method tests for !=.

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

Converts the given value to a String. 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.