1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-04-28 09:53:19 +02:00

Be more precise about printing in compound-types.md (#1421)

Fixes #1412.
This commit is contained in:
Martin Geisler 2023-10-24 11:32:34 +02:00 committed by GitHub
parent 77c55ef10e
commit e6e4d50eef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,7 +12,7 @@ Array assignment and access:
fn main() { fn main() {
let mut a: [i8; 10] = [42; 10]; let mut a: [i8; 10] = [42; 10];
a[5] = 0; a[5] = 0;
println!("a: {:?}", a); println!("a: {a:?}");
} }
``` ```
@ -39,10 +39,10 @@ Arrays:
* We can use literals to assign values to arrays. * We can use literals to assign values to arrays.
* In the main function, the print statement asks for the debug implementation with the `?` format * The `println!` macro asks for the debug implementation with the `?` format
parameter: `{}` gives the default output, `{:?}` gives the debug output. We parameter: `{}` gives the default output, `{:?}` gives the debug output. Types such as
could also have used `{a}` and `{a:?}` without specifying the value after the integers and strings implement the default output, but arrays only implement the debug output.
format string. This means that we must use debug output here.
* Adding `#`, eg `{a:#?}`, invokes a "pretty printing" format, which can be easier to read. * Adding `#`, eg `{a:#?}`, invokes a "pretty printing" format, which can be easier to read.