diff --git a/src/custom_types/structs.md b/src/custom_types/structs.md index e863e0ee6b..b7f84c2fa4 100644 --- a/src/custom_types/structs.md +++ b/src/custom_types/structs.md @@ -16,7 +16,7 @@ struct Person<'a> { } // A unit struct -struct Nil; +struct Unit; // A tuple struct struct Pair(i32, f32); @@ -70,7 +70,7 @@ fn main() { }; // Instantiate a unit struct - let _nil = Nil; + let _unit = Unit; // Instantiate a tuple struct let pair = Pair(1, 0.1); diff --git a/src/trait/clone.md b/src/trait/clone.md index acd531632a..1b9d953b71 100644 --- a/src/trait/clone.md +++ b/src/trait/clone.md @@ -1,30 +1,30 @@ # Clone When dealing with resources, the default behavior is to transfer them during -assignments or function calls. However, sometimes we need to make a +assignments or function calls. However, sometimes we need to make a copy of the resource as well. -The [`Clone`][clone] trait helps us do exactly this. Most commonly, we can +The [`Clone`][clone] trait helps us do exactly this. Most commonly, we can use the `.clone()` method defined by the `Clone` trait. ```rust,editable // A unit struct without resources #[derive(Debug, Clone, Copy)] -struct Nil; +struct Unit; // A tuple struct with resources that implements the `Clone` trait #[derive(Clone, Debug)] struct Pair(Box, Box); fn main() { - // Instantiate `Nil` - let nil = Nil; - // Copy `Nil`, there are no resources to move - let copied_nil = nil; + // Instantiate `Unit` + let unit = Unit; + // Copy `Unit`, there are no resources to move + let copied_unit = unit; - // Both `Nil`s can be used independently - println!("original: {:?}", nil); - println!("copy: {:?}", copied_nil); + // Both `Unit`s can be used independently + println!("original: {:?}", unit); + println!("copy: {:?}", copied_unit); // Instantiate `Pair` let pair = Pair(Box::new(1), Box::new(2)); @@ -37,7 +37,7 @@ fn main() { // Error! `pair` has lost its resources //println!("original: {:?}", pair); // TODO ^ Try uncommenting this line - + // Clone `moved_pair` into `cloned_pair` (resources are included) let cloned_pair = moved_pair.clone(); // Drop the original pair using std::mem::drop @@ -52,4 +52,4 @@ fn main() { } ``` -[clone]: https://doc.rust-lang.org/std/clone/trait.Clone.html \ No newline at end of file +[clone]: https://doc.rust-lang.org/std/clone/trait.Clone.html