std::str - Rust
Description: API documentation for the Rust `str` mod in crate `std`.
Keywords: rust, rustlang, rust-lang, str

# Module std::str 1.0.0 [−] [src]

Unicode string slices.

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

See also the `str` primitive type.

## Modules

pattern | [ Experimental ] The string Pattern API.

## Structs

Bytes | An iterator over the bytes of a string slice.
CharIndices | An iterator over the `char`s of a string slice, and their positions.
Chars | An iterator over the `char`s of a string slice.
EncodeUtf16 | An iterator of `u16` over the string encoded as UTF-16.
Lines | An iterator over the lines of a string, as string slices.
LinesAny | [ Deprecated ] Created with the method `lines_any`.
MatchIndices | Created with the method `match_indices`.
Matches | Created with the method `matches`.
ParseBoolError | An error returned when parsing a `bool` using `from_str` fails
RMatchIndices | Created with the method `rmatch_indices`.
RMatches | Created with the method `rmatches`.
RSplit | Created with the method `rsplit`.
RSplitN | Created with the method `rsplitn`.
RSplitTerminator | Created with the method `rsplit_terminator`.
Split | Created with the method `split`.
SplitN | Created with the method `splitn`.
SplitTerminator | Created with the method `split_terminator`.
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 sequence of `u8` as a string.

## Traits

FromStr | A trait to abstract the idea of creating a new instance of a type from a string.

## Functions

from_boxed_utf8_unchecked⚠ | Converts a boxed slice of bytes to a boxed string slice without checking that the string contains valid UTF-8.
from_utf8 | Converts a slice of bytes to a string slice.
from_utf8_mut | Converts a mutable slice of bytes to a mutable string slice.
from_utf8_unchecked⚠ | Converts a slice of bytes to a string slice without checking that the string contains valid UTF-8.
from_utf8_unchecked_mut⚠ | Converts a slice of bytes to a string slice without checking that the string contains valid UTF-8; mutable version.

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
↑
  Move up in search results
↓
  Move down in search results
↹
  Switch tab
⏎
  Go to active search result
+ / -
  Collapse/expand all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)