1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-02-13 16:32:23 +02:00

Added an Alternative way for printing struct and declaring a string. (#1773)

Knowing to_string method is good for learner to use at some situation. 
Knowing print complete struct object can be useful while debug.

---------

Co-authored-by: Dustin J. Mitchell <djmitche@google.com>
This commit is contained in:
Manichand Kondapaka 2024-02-03 02:18:03 +05:30 committed by GitHub
parent a673efbc14
commit faea6894e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 0 deletions

View File

@ -54,5 +54,10 @@ all `str` methods on a `String`.
out-of-bounds.
- To a substring by using `s3[0..4]`, where that slice is on character
boundaries or not.
- Many types can be converted to a string with the
[`to_string`](https://doc.rust-lang.org/std/string/trait.ToString.html#tymethod.to_string)
method. This trait is automatically implemented for all types that implement
`Display`, so anything that can be formatted can also be converted to a
string.
</details>

View File

@ -53,4 +53,7 @@ later, but this is enough for subsequent slides and exercises to use strings.
}
```
- Using `{:?}` is a convenient way to print array/vector/struct of values for
debugging purposes, and it's commonly used in code.
</details>