1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-03-22 06:51:58 +02:00

Update from-into.md (#245)

Explaining how those traits are used in practice and when you should use one over another.
This commit is contained in:
Igor Petruk 2023-01-23 13:18:34 +00:00 committed by GitHub
parent 12c3e2989d
commit 05cc2ff480
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,3 +23,11 @@ fn main() {
println!("{s}, {addr}, {one}, {bigger}");
}
```
<details>
* That's why it is common to only implement `From`, as your type will get `Into` implementation too.
* When declaring a function argument input type like "anything that can be converted into a `String`", the rule is opposite, you should use `Into`.
Your function will accept types that implement `From` and those that _only_ implement `Into`.
</details>