Skip to content

Commit

Permalink
Merge pull request #1326 from rossmacarthur/fix/unit-called-nil
Browse files Browse the repository at this point in the history
Do not use "nil" to refer to `()`
  • Loading branch information
steveklabnik authored Apr 6, 2020
2 parents 25482c1 + 2876b85 commit 05a98da
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/custom_types/structs.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct Person<'a> {
}
// A unit struct
struct Nil;
struct Unit;
// A tuple struct
struct Pair(i32, f32);
Expand Down Expand Up @@ -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);
Expand Down
24 changes: 12 additions & 12 deletions src/trait/clone.md
Original file line number Diff line number Diff line change
@@ -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<i32>, Box<i32>);
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));
Expand All @@ -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
Expand All @@ -52,4 +52,4 @@ fn main() {
}
```

[clone]: https://doc.rust-lang.org/std/clone/trait.Clone.html
[clone]: https://doc.rust-lang.org/std/clone/trait.Clone.html

0 comments on commit 05a98da

Please sign in to comment.