2018-08-30 14:18:55 +02:00
|
|
|
//@ run-pass
|
2013-06-28 17:47:44 -07:00
|
|
|
|
|
|
|
pub trait Clone2 {
|
2015-06-09 16:26:21 -04:00
|
|
|
/// Returns a copy of the value. The contents of boxes
|
2013-06-28 17:47:44 -07:00
|
|
|
/// are copied to maintain uniqueness, while the contents of
|
|
|
|
/// managed pointers are not copied.
|
|
|
|
fn clone(&self) -> Self;
|
|
|
|
}
|
|
|
|
|
|
|
|
trait Getter<T: Clone> {
|
|
|
|
fn do_get(&self) -> T;
|
|
|
|
|
|
|
|
fn do_get2(&self) -> (T, T) {
|
|
|
|
let x = self.do_get();
|
|
|
|
(x.clone(), x.clone())
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-03-25 17:06:52 -07:00
|
|
|
impl Getter<isize> for isize {
|
|
|
|
fn do_get(&self) -> isize { *self }
|
2013-06-28 17:47:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: Clone> Getter<T> for Option<T> {
|
2014-10-14 23:05:01 -07:00
|
|
|
fn do_get(&self) -> T { self.as_ref().unwrap().clone() }
|
2013-06-28 17:47:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-25 00:43:37 -07:00
|
|
|
pub fn main() {
|
2013-06-28 17:47:44 -07:00
|
|
|
assert_eq!(3.do_get2(), (3, 3));
|
2014-05-25 03:10:11 -07:00
|
|
|
assert_eq!(Some("hi".to_string()).do_get2(), ("hi".to_string(), "hi".to_string()));
|
2013-06-28 17:47:44 -07:00
|
|
|
}
|