Module collections::str
[−]
[src]
Unicode string manipulation (the str
`str` type).
Rust's str
`strtype is one of the core primitive types of the language.
` type is one of the core primitive types of the language. &str
`&stris the borrowed string type. This type of string can only be created from other strings, unless it is a
`
is the borrowed string type. This type of string can only be created from
other strings, unless it is a &'static str
`&'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
`&str`:
let s = "Hello, world.";
This &str
`&stris a
` is a &'static str
`&'static str, which is the type of string literals. They're
`, which is the type of string literals.
They're 'static
`'static` because literals are available for the entire lifetime of
the program.
You can get a non-'static
`'static`
&str
`&strby taking a slice of a
` by taking a slice of a String
`String`:
let s = &some_string;
Representation
Rust's string type, str
`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 str
`strs have direct mappings to slices:
`s have direct mappings to slices: &str
`&stris the same as
`
is the same as &[u8]
`&[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] |