update: answer reference in "type-conversions"

This commit is contained in:
Somoku
2022-08-29 15:52:39 +08:00
parent e7b4b0215f
commit 679bc95397
7 changed files with 19 additions and 7 deletions

View File

@ -100,3 +100,5 @@ fn main() {
}
}
```
> 你可以在[这里](https://github.com/sunface/rust-by-practice/blob/master/solutions/type-conversions/as.md)找到答案(在 solutions 路径下)

View File

@ -6,7 +6,7 @@
需要注意的是,当使用 `into` 方法时,你需要进行显式地类型标注,因为编译器很可能无法帮我们推导出所需的类型。
来看一个例子,我们可以简单的将 `&str` 转换成 `String``
来看一个例子,我们可以简单的将 `&str` 转换成 `String`
```rust
fn main() {
let my_str = "hello";
@ -107,7 +107,7 @@ fn main() {
### TryFrom/TryInto
类似于 `From` 和 `Into`, `TryFrom` 和 `TryInto` 也是用于类型转换的泛型特。
类似于 `From` 和 `Into`, `TryFrom` 和 `TryInto` 也是用于类型转换的泛型特
但是又与 `From/Into` 不同, `TryFrom` 和 `TryInto` 可以对转换后的失败进行处理,然后返回一个 `Result`。
@ -165,4 +165,6 @@ fn main() {
println!("Success!")
}
```
```
> 你可以在[这里](https://github.com/sunface/rust-by-practice/blob/master/solutions/type-conversions/from-into.md)找到答案(在 solutions 路径下)

View File

@ -41,7 +41,7 @@ fn main() {
println!("Success!")
}
```
```
3. 🌟🌟 还可以为自定义类型实现 `FromStr` 特征
@ -163,4 +163,6 @@ fn main() {
// literal
assert_eq!(b"Rust", &[82, 117, 115, 116]);
}
```
```
> 你可以在[这里](https://github.com/sunface/rust-by-practice/blob/master/solutions/type-conversions/others.md)找到答案(在 solutions 路径下)