File tree 1 file changed +23
-0
lines changed 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change 18
18
//! them cheap and safe to copy. For other types copies must be made
19
19
//! explicitly, by convention implementing the `Clone` trait and calling
20
20
//! the `clone` method.
21
+ //!
22
+ //! Basic usage example:
23
+ //!
24
+ //! ```
25
+ //! let s = String::new(); // String type implements Clone
26
+ //! let copy = s.clone(); // so we can clone it
27
+ //! ```
28
+ //!
29
+ //! To easily implement the Clone trait, you can also use
30
+ //! `#[derive(Clone)]`. Example:
31
+ //!
32
+ //! ```
33
+ //! #[derive(Clone)] // we add the Clone trait to Morpheus struct
34
+ //! struct Morpheus {
35
+ //! blue_pill: f32,
36
+ //! red_pill: i64,
37
+ //! }
38
+ //!
39
+ //! fn main() {
40
+ //! let f = Morpheus { blue_pill: 0.0, red_pill: 0 };
41
+ //! let copy = f.clone(); // and now we can clone it!
42
+ //! }
43
+ //! ```
21
44
22
45
#![ stable( feature = "rust1" , since = "1.0.0" ) ]
23
46
You can’t perform that action at this time.
0 commit comments