diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2016-03-22 01:12:59 +0100 |
|---|---|---|
| committer | ggomez <guillaume1.gomez@gmail.com> | 2016-03-22 18:18:01 +0100 |
| commit | b3aa35e756c4d1c0d015a502b2e5b854752c99e7 (patch) | |
| tree | 00c050a6be86f3df92ba4be7c0029ebca705a7e7 | |
| parent | 0168dc7c5904701983c280cb4fa0fb0c0fa692c5 (diff) | |
| download | rust-b3aa35e756c4d1c0d015a502b2e5b854752c99e7.tar.gz rust-b3aa35e756c4d1c0d015a502b2e5b854752c99e7.zip | |
Add doc example to clone trait
| -rw-r--r-- | src/libcore/clone.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/libcore/clone.rs b/src/libcore/clone.rs index b1f63ad71ca..a793502e58d 100644 --- a/src/libcore/clone.rs +++ b/src/libcore/clone.rs @@ -18,6 +18,29 @@ //! them cheap and safe to copy. For other types copies must be made //! explicitly, by convention implementing the `Clone` trait and calling //! the `clone` method. +//! +//! Basic usage example: +//! +//! ``` +//! let s = String::new(); // String type implements Clone +//! let copy = s.clone(); // so we can clone it +//! ``` +//! +//! To easily implement the Clone trait, you can also use +//! `#[derive(Clone)]`. Example: +//! +//! ``` +//! #[derive(Clone)] // we add the Clone trait to Morpheus struct +//! struct Morpheus { +//! blue_pill: f32, +//! red_pill: i64, +//! } +//! +//! fn main() { +//! let f = Morpheus { blue_pill: 0.0, red_pill: 0 }; +//! let copy = f.clone(); // and now we can clone it! +//! } +//! ``` #![stable(feature = "rust1", since = "1.0.0")] |
