]>
Commit | Line | Data |
---|---|---|
970d7e83 LB |
1 | // Copyright 2013 The Rust Project Developers. See the COPYRIGHT |
2 | // file at the top-level directory of this distribution and at | |
3 | // http://rust-lang.org/COPYRIGHT. | |
4 | // | |
5 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
6 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
7 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
8 | // option. This file may not be copied, modified, or distributed | |
9 | // except according to those terms. | |
1a4d82fc JJ |
10 | // |
11 | // ignore-lexer-test FIXME #15877 | |
970d7e83 LB |
12 | |
13 | pub trait Clone2 { | |
14 | /// Returns a copy of the value. The contents of owned pointers | |
15 | /// are copied to maintain uniqueness, while the contents of | |
16 | /// managed pointers are not copied. | |
17 | fn clone(&self) -> Self; | |
18 | } | |
19 | ||
970d7e83 LB |
20 | trait Getter<T: Clone> { |
21 | fn do_get(&self) -> T; | |
22 | ||
23 | fn do_get2(&self) -> (T, T) { | |
24 | let x = self.do_get(); | |
25 | (x.clone(), x.clone()) | |
26 | } | |
27 | ||
28 | } | |
29 | ||
30 | impl Getter<int> for int { | |
31 | fn do_get(&self) -> int { *self } | |
32 | } | |
33 | ||
34 | impl<T: Clone> Getter<T> for Option<T> { | |
1a4d82fc | 35 | fn do_get(&self) -> T { self.as_ref().unwrap().clone() } |
970d7e83 LB |
36 | } |
37 | ||
38 | ||
1a4d82fc | 39 | pub fn main() { |
970d7e83 | 40 | assert_eq!(3.do_get2(), (3, 3)); |
1a4d82fc | 41 | assert_eq!(Some("hi".to_string()).do_get2(), ("hi".to_string(), "hi".to_string())); |
970d7e83 | 42 | } |