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

@ -103,3 +103,5 @@ fn main() {
println!("Success!");
}
```
> You can find the solutions [here](https://github.com/sunface/rust-by-practice/blob/master/solutions/type-conversions/as.md)(under the solutions path), but only use it when you need it

View File

@ -168,4 +168,6 @@ fn main() {
println!("Success!");
}
```
```
> You can find the solutions [here](https://github.com/sunface/rust-by-practice/blob/master/solutions/type-conversions/from-into.md)(under the solutions path), but only use it when you need it

View File

@ -162,4 +162,6 @@ fn main() {
// literal
assert_eq!(b"Rust", &[82, 117, 115, 116]);
}
```
```
> You can find the solutions [here](https://github.com/sunface/rust-by-practice/blob/master/solutions/type-conversions/others.md)(under the solutions path), but only use it when you need it

0
zh-CN/deploy → zh-CN/deploy.sh Executable file → Normal file
View File

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 路径下)