diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-01-15 14:11:46 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-01-15 14:11:46 -0800 |
| commit | d7009e6f31c63fc2e0ba2153e6354ce44663ddb4 (patch) | |
| tree | 2934dfc9da115acef377548e72758540d09e2f01 /src/doc/trpl/pointers.md | |
| parent | b555528f0ba1cc091bac689f7b8b8576c4573d18 (diff) | |
| parent | 07f723f19bdf1054d140fc713f72f04a2f1b4258 (diff) | |
| download | rust-d7009e6f31c63fc2e0ba2153e6354ce44663ddb4.tar.gz rust-d7009e6f31c63fc2e0ba2153e6354ce44663ddb4.zip | |
rollup merge of #21105: csouth3/kill-box-import
Closes #21093. r? @steveklabnik cc @alexcrichton I tested with `make check-docs` and this passes that. Hope that was enough.
Diffstat (limited to 'src/doc/trpl/pointers.md')
| -rw-r--r-- | src/doc/trpl/pointers.md | 10 |
1 files changed, 0 insertions, 10 deletions
diff --git a/src/doc/trpl/pointers.md b/src/doc/trpl/pointers.md index 0c72e5c404c..6832d75245e 100644 --- a/src/doc/trpl/pointers.md +++ b/src/doc/trpl/pointers.md @@ -455,7 +455,6 @@ fn rc_succ(x: Rc<int>) -> int { *x + 1 } Note that the caller of your function will have to modify their calls slightly: ```{rust} -# use std::boxed::Box; use std::rc::Rc; fn succ(x: &int) -> int { *x + 1 } @@ -478,7 +477,6 @@ those contents. heap allocation in Rust. Creating a box looks like this: ```{rust} -# use std::boxed::Box; let x = Box::new(5i); ``` @@ -486,7 +484,6 @@ Boxes are heap allocated and they are deallocated automatically by Rust when they go out of scope: ```{rust} -# use std::boxed::Box; { let x = Box::new(5i); @@ -507,7 +504,6 @@ You don't need to fully grok the theory of affine types or regions to grok boxes, though. As a rough approximation, you can treat this Rust code: ```{rust} -# use std::boxed::Box; { let x = Box::new(5i); @@ -548,7 +544,6 @@ for more detail on how lifetimes work. Using boxes and references together is very common. For example: ```{rust} -# use std::boxed::Box; fn add_one(x: &int) -> int { *x + 1 } @@ -566,7 +561,6 @@ function, and since it's only reading the value, allows it. We can borrow `x` multiple times, as long as it's not simultaneous: ```{rust} -# use std::boxed::Box; fn add_one(x: &int) -> int { *x + 1 } @@ -583,7 +577,6 @@ fn main() { Or as long as it's not a mutable borrow. This will error: ```{rust,ignore} -# use std::boxed::Box; fn add_one(x: &mut int) -> int { *x + 1 } @@ -610,7 +603,6 @@ Sometimes, you need a recursive data structure. The simplest is known as a ```{rust} -# use std::boxed::Box; #[derive(Show)] enum List<T> { Cons(T, Box<List<T>>), @@ -666,7 +658,6 @@ In many languages with pointers, you'd return a pointer from a function so as to avoid copying a large data structure. For example: ```{rust} -# use std::boxed::Box; struct BigStruct { one: int, two: int, @@ -695,7 +686,6 @@ than the hundred `int`s that make up the `BigStruct`. This is an antipattern in Rust. Instead, write this: ```{rust} -# use std::boxed::Box; struct BigStruct { one: int, two: int, |
