std::str

Primitive Type str

String slices.

The str type, also called a 'string slice', is the most primitive string type. It is usually seen in its borrowed form, &str. It is also the type of string literals, &'static str.

Strings slices are always valid UTF-8.

This documentation describes a number of methods and trait implementations on the str type. For technical reasons, there is additional, separate documentation in the std::str module as well.

Examples

String literals are string slices:

let hello = "Hello, world!";

// with an explicit type annotation
let hello: &'static str = "Hello, world!";

They are 'static because they're stored directly in the final binary, and so will be valid for the 'static登录查看完整内容