From 2a6b9c6a319507908d22d8a754a92f0aac15f4e4 Mon Sep 17 00:00:00 2001 From: wangmengc Date: Fri, 17 May 2024 13:35:56 +0800 Subject: [PATCH 1/2] update src/cargo/conventions.md --- english/src/cargo/conventions.md | 6 +++--- src/cargo/conventions.md | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/english/src/cargo/conventions.md b/english/src/cargo/conventions.md index 6e819660..2335104f 100644 --- a/english/src/cargo/conventions.md +++ b/english/src/cargo/conventions.md @@ -25,9 +25,9 @@ foo └── my_other_bin.rs ``` -To tell `cargo` to compile or run this binary as opposed to the default or other -binaries, we just pass `cargo` the `--bin my_other_bin` flag, where `my_other_bin` -is the name of the binary we want to work with. +To tell `cargo` to only compile or run this binary, we just pass `cargo` the +`--bin my_other_bin` flag, where `my_other_bin` is the name of the binary we +want to work with. In addition to extra binaries, `cargo` supports [more features] such as benchmarks, tests, and examples. diff --git a/src/cargo/conventions.md b/src/cargo/conventions.md index 504aa1af..379d3d25 100644 --- a/src/cargo/conventions.md +++ b/src/cargo/conventions.md @@ -22,7 +22,7 @@ foo └── my_other_bin.rs ``` -为了使得 `cargo` 编译或运行这个二进制可执行文件而不是默认或其他二进制可执行文件,我们只需给 `cargo` 增加一个参数 `--bin my_other_bin`,其中 `my_other_bin` 是我们想要使用的二进制可执行文件的名称。 +为了使得 `cargo` 只编译或运行这个二进制可执行文件,我们只需给 `cargo` 增加一个参数 `--bin my_other_bin`,其中 `my_other_bin` 是我们想要使用的二进制可执行文件的名称。 除了可添加其他二进制可执行文件外,`cargo` 还支持[更多功能][more features],如基准测试,测试和示例。 From 78fc6e5da9e31043ac4cf61b934590fdd76b7862 Mon Sep 17 00:00:00 2001 From: wangmengc Date: Tue, 10 Sep 2024 14:52:50 +0800 Subject: [PATCH 2/2] updata src/conversion/from_into.md --- english/src/conversion/from_into.md | 10 +++++----- src/conversion/from_into.md | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/english/src/conversion/from_into.md b/english/src/conversion/from_into.md index 266d10f2..d927cdd7 100644 --- a/english/src/conversion/from_into.md +++ b/english/src/conversion/from_into.md @@ -51,22 +51,22 @@ convert into as the compiler is unable to determine this most of the time. However this is a small trade-off considering we get the functionality for free. ```rust,editable -use std::convert::From; +use std::convert::Into; #[derive(Debug)] struct Number { value: i32, } -impl From for Number { - fn from(item: i32) -> Self { - Number { value: item } +impl Into for i32 { + fn into(self) -> Number { + Number { value: self } } } fn main() { let int = 5; - // Try removing the type declaration + // Try removing the type annotation let num: Number = int.into(); println!("My number is {:?}", num); } diff --git a/src/conversion/from_into.md b/src/conversion/from_into.md index d6b0ea29..28ae2a38 100644 --- a/src/conversion/from_into.md +++ b/src/conversion/from_into.md @@ -42,22 +42,22 @@ fn main() { 使用 `Into` trait 通常要求指明要转换到的类型,因为编译器大多数时候不能推断它。不过考虑到我们免费获得了 `Into`,这点代价不值一提。 ```rust,editable -use std::convert::From; +use std::convert::Into; #[derive(Debug)] struct Number { value: i32, } -impl From for Number { - fn from(item: i32) -> Self { - Number { value: item } +impl Into for i32 { + fn into(self) -> Number { + Number { value: self } } } fn main() { let int = 5; - // 试试删除类型说明 + // 试试删除类型注释 let num: Number = int.into(); println!("My number is {:?}", num); }