|
1.
|
|
|
This prints:
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-pointers.md:607 src/doc/guide-strings.md:183
src/doc/guide-strings.md:209
|
|
2.
|
|
|
% The Guide to Rust Strings
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-strings.md:2
|
|
3.
|
|
|
Strings are an important concept to master in any programming language. If you come from a managed language background, you may be surprised at the complexity of string handling in a systems programming language. Efficient access and allocation of memory for a dynamically sized structure involves a lot of details. Luckily, Rust has lots of tools to help us here.
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-strings.md:8
|
|
4.
|
|
|
A **string** 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 contain null bytes.
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-strings.md:12
|
|
5.
|
|
|
Rust has two main types of strings: `&str` and `String`.
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-strings.md:14 src/doc/guide.md:1460
|
|
6.
|
|
|
# &str
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-strings.md:16
|
|
7.
|
|
|
The first kind is a `&str`. This is pronounced a 'string slice'. String literals are of the type `&str`:
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-strings.md:19
|
|
8.
|
|
|
```{rust} let string = "Hello there."; ```
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-strings.md:23 src/doc/guide.md:1467
|
|
9.
|
|
|
Like any Rust type, string slices have an associated lifetime. A string literal is a `&'static str`. A string slice can be written without an explicit lifetime in many cases, such as in function arguments. In these cases the lifetime will be inferred:
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-strings.md:28
|
|
10.
|
|
|
```{rust}
fn takes_slice(slice: &str) {
println!("Got: {}", slice);
}
```
|
|
|
type: Plain text
|
|
|
represents a line break.
Start a new line in the equivalent position in the translation.
|
|
|
represents a space character.
Enter a space in the equivalent position in the translation.
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-strings.md:34
|