Module std::str

1.0.0· source[]
Expand description

Unicode string slices.

See also the str primitive type.

The &str type is one of the two main string types, the other being String. Unlike its String counterpart, its contents are borrowed.

Basic Usage

A basic string declaration of &str type:

let hello_world = "Hello, World!";
Run

Here we have declared a string literal, also known as a string slice. String literals have a static lifetime, which means the string hello_world is guaranteed to be valid for the duration of the entire program. We can explicitly specify hello_world’s lifetime as well:

let hello_world: &'static str = "Hello, world!";
Run

Modules

patternExperimental

The string Pattern API.

Structs

An iterator over the bytes of a string slice.

An iterator over the chars of a string slice, and their positions.

An iterator over the chars of a string slice.

An iterator of u16 over the string encoded as UTF-16.

The return type of str::escape_debug.

An iterator over the lines of a string, as string slices.

LinesAnyDeprecated

Created with the method lines_any.

Created with the method match_indices.

Created with the method matches.

An error returned when parsing a bool using from_str fails

Created with the method rmatch_indices.

Created with the method rmatches.

Created with the method rsplit.

Created with the method rsplitn.

Created with the method rsplit_terminator.

Created with the method split.

An iterator over the non-ASCII-whitespace substrings of a string, separated by any amount of ASCII whitespace.

An iterator over the substrings of a string, terminated by a substring matching to a predicate function Unlike Split, it contains the matched part as a terminator of the subslice.

Created with the method splitn.

Created with the method split_terminator.

An iterator over the non-whitespace substrings of a string, separated by any amount of whitespace.

Errors which can occur when attempting to interpret a sequence of u8 as a string.

Traits

Parse a value from a string

Functions

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

Converts a slice of bytes to a string slice.

Converts a mutable slice of bytes to a mutable string slice.

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

Converts a slice of bytes to a string slice without checking that the string contains valid UTF-8; mutable version.