diff options
| author | bors <bors@rust-lang.org> | 2016-03-24 09:25:02 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2016-03-24 09:25:02 -0700 |
| commit | dcfb8d72e99425686376298fd793715f35b5d512 (patch) | |
| tree | a202c287d30ee142f1931f5dd02bee256324d7e7 /src/libcore | |
| parent | dc1f6831eb0d0e5cca16395f14b7406ff85c4c3d (diff) | |
| parent | b2dfb7c0a267d6f2adb9cbde1e157fc136fcaaab (diff) | |
| download | rust-dcfb8d72e99425686376298fd793715f35b5d512.tar.gz rust-dcfb8d72e99425686376298fd793715f35b5d512.zip | |
Auto merge of #32465 - steveklabnik:rollup, r=steveklabnik
Rollup of 6 pull requests - Successful merges: #32276, #32416, #32452, #32459, #32462, #32464 - Failed merges:
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/clone.rs | 23 | ||||
| -rw-r--r-- | src/libcore/option.rs | 10 |
2 files changed, 26 insertions, 7 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")] diff --git a/src/libcore/option.rs b/src/libcore/option.rs index dd60e8797a9..beed2075d04 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -93,16 +93,12 @@ //! let msg = Some("howdy"); //! //! // Take a reference to the contained string -//! match msg { -//! Some(ref m) => println!("{}", *m), -//! None => (), +//! if let Some(ref m) = msg { +//! println!("{}", *m); //! } //! //! // Remove the contained string, destroying the Option -//! let unwrapped_msg = match msg { -//! Some(m) => m, -//! None => "default message", -//! }; +//! let unwrapped_msg = msg.unwrap_or("default message"); //! ``` //! //! Initialize a result to `None` before a loop: |
