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 String
s are valid UTF-8.
Converts a String
into a byte vector.
This consumes the String
, so we do not need to copy its contents.
Converts a String
into a mutable string slice.
Appends a given string slice onto the end of this String
.
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.
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.
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.
Returns a mutable reference to the contents of this String
.
Returns the length of this String
, in bytes, not char
s 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 char
s.
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.
Trait Implementations
Performs the +=
operation. Read more
Mutably borrows from an owned value. Read more
Implements display for the String type.
This would never run in normal Rust, so anything can be written out.
Implement from for &str, but don’t do anything other than returning an empty instance of itself.
Convert from Rust’s String type to this String type automatically.
Auto Trait Implementations
impl RefUnwindSafe for String
impl UnwindSafe for String
Blanket Implementations
Mutably borrows from an owned value. Read more