Module std::str
[−]
[src]
Unicode string manipulation (the str type).
Rust's str type is one of the core primitive types of the language. &str
is the borrowed string type. This type of string can only be created from
other strings, unless it is a &'static str (see below). It is not possible
to move out of borrowed strings because they are owned elsewhere.
Examples
Here's some code that uses a &str:
let s = "Hello, world.";
This &str is a &'static str, which is the type of string literals.
They're 'static because literals are available for the entire lifetime of
the program.
You can get a non-'static &str by taking a slice of a String:
let s = &some_string;
Representation
Rust's string type, str, is a sequence of Unicode scalar values encoded as
a stream of UTF-8 bytes. All strings are
guaranteed to be validly encoded UTF-8 sequences. Additionally, strings are
not null-terminated and can thus contain null bytes.
The actual representation of strs have direct mappings to slices: &str
is the same as &[u8].
Modules
| pattern |
[Unstable] The string Pattern API. |
Structs
| Bytes |
External iterator for a string's bytes.
Use with the |
| CharIndices |
Iterator for a string's characters and their byte offsets. |
| Chars |
Iterator for the char (representing Unicode Scalar Values) of a string |
| Lines |
Created with the method |
| LinesAny |
Created with the method |
| ParseBoolError |
An error returned when parsing a |
| RSplit |
/// Created with the method |
| RSplitN |
/// Created with the method |
| RSplitTerminator |
/// Created with the method |
| Split |
/// Created with the method |
| SplitN |
/// Created with the method |
| SplitTerminator |
/// Created with the method |
| SplitWhitespace |
An iterator over the non-whitespace substrings of a string, separated by any amount of whitespace. |
| Utf8Error |
Errors which can occur when attempting to interpret a byte slice as a |
| CharRange |
[Unstable] Struct that contains a |
| Decompositions |
[Deprecated] External iterator for a string decomposition's characters. |
| GraphemeIndices |
[Unstable] External iterator for grapheme clusters and byte offsets. |
| Graphemes |
[Unstable] External iterator for a string's grapheme clusters. |
| MatchIndices |
[Unstable] /// Created with the method |
| Matches |
[Unstable] /// Created with the method |
| RMatchIndices |
[Unstable] /// Created with the method |
| RMatches |
[Unstable] /// Created with the method |
| Recompositions |
[Deprecated] External iterator for a string recomposition's characters. |
| Utf16Units |
[Unstable] External iterator for a string's UTF16 codeunits. |
Traits
| FromStr |
A trait to abstract the idea of creating a new instance of a type from a string. |
Functions
| from_utf8 |
Converts a slice of bytes to a string slice without performing any allocations. |
| from_utf8_unchecked |
Converts a slice of bytes to a string slice without checking that the string contains valid UTF-8. |
Type Definitions
| Words | [Deprecated] |