Skip to content

Commit

Permalink
Added an Alternative way for printing struct and declaring a string. (g…
Browse files Browse the repository at this point in the history
…oogle#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 <[email protected]>
  • Loading branch information
mani-chand and djmitche authored Feb 2, 2024
1 parent a673efb commit faea689
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/std-types/string.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>
3 changes: 3 additions & 0 deletions src/types-and-values/strings.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>

0 comments on commit faea689

Please sign in to comment.