Merge pull request #444 from maorit/format_code_type_conversion_from_into

format code: format code in `type-conversions/from-into`
This commit is contained in:
Sunface
2023-08-11 10:49:39 +08:00
committed by GitHub
3 changed files with 14 additions and 20 deletions

View File

@ -27,7 +27,6 @@ Some implementations of `From` trait can be found [here](https://doc.rust-lang.o
1. 🌟🌟🌟 1. 🌟🌟🌟
```rust,editable ```rust,editable
fn main() { fn main() {
// impl From<bool> for i32 // impl From<bool> for i32
let i1: i32 = false.into(); let i1: i32 = false.into();
@ -51,7 +50,6 @@ fn main() {
### Implement `From` for custom types ### Implement `From` for custom types
2. 🌟🌟 2. 🌟🌟
```rust,editable ```rust,editable
// From is now included in `std::prelude`, so there is no need to introduce it into the current scope // From is now included in `std::prelude`, so there is no need to introduce it into the current scope
// use std::convert::From; // use std::convert::From;
@ -78,7 +76,6 @@ fn main() {
3. 🌟🌟🌟 When performing error handling it is often useful to implement `From` trait for our own error type. Then we can use `?` to automatically convert the underlying error type to our own error type. 3. 🌟🌟🌟 When performing error handling it is often useful to implement `From` trait for our own error type. Then we can use `?` to automatically convert the underlying error type to our own error type.
```rust,editable ```rust,editable
use std::fs; use std::fs;
use std::io; use std::io;
use std::num; use std::num;

View File

@ -24,7 +24,6 @@ fn main() {
1. 🌟🌟🌟 1. 🌟🌟🌟
```rust,editable ```rust,editable
fn main() { fn main() {
// impl From<bool> for i32 // impl From<bool> for i32
let i1: i32 = false.into(); let i1: i32 = false.into();
@ -47,7 +46,6 @@ fn main() {
### 为自定义类型实现 `From` 特征 ### 为自定义类型实现 `From` 特征
2. 🌟🌟 2. 🌟🌟
```rust,editable ```rust,editable
// From 被包含在 `std::prelude` 中,因此我们没必要手动将其引入到当前作用域来 // From 被包含在 `std::prelude` 中,因此我们没必要手动将其引入到当前作用域来
// use std::convert::From; // use std::convert::From;
@ -74,7 +72,6 @@ fn main() {
3. 🌟🌟🌟 当执行错误处理时,为我们自定义的错误类型实现 `From` 特征是非常有用。这样就可以通过 `?` 自动将某个错误类型转换成我们自定义的错误类型 3. 🌟🌟🌟 当执行错误处理时,为我们自定义的错误类型实现 `From` 特征是非常有用。这样就可以通过 `?` 自动将某个错误类型转换成我们自定义的错误类型
```rust,editable ```rust,editable
use std::fs; use std::fs;
use std::io; use std::io;
use std::num; use std::num;