2018-08-30 14:18:55 +02:00
|
|
|
// run-pass
|
2018-08-31 15:02:01 +02:00
|
|
|
#![allow(non_snake_case)]
|
|
|
|
#![allow(non_camel_case_types)]
|
|
|
|
|
2013-03-12 19:32:14 -07:00
|
|
|
trait repeat<A> { fn get(&self) -> A; }
|
2012-07-18 11:01:54 -07:00
|
|
|
|
2014-05-05 18:56:44 -07:00
|
|
|
impl<A:Clone + 'static> repeat<A> for Box<A> {
|
2013-07-02 12:47:32 -07:00
|
|
|
fn get(&self) -> A {
|
|
|
|
(**self).clone()
|
|
|
|
}
|
2012-07-18 11:01:54 -07:00
|
|
|
}
|
|
|
|
|
2019-05-28 14:47:21 -04:00
|
|
|
fn repeater<A:Clone + 'static>(v: Box<A>) -> Box<dyn repeat<A>+'static> {
|
2021-08-25 02:39:40 +02:00
|
|
|
Box::new(v) as Box<dyn repeat<A>+'static> // No
|
2012-07-18 11:01:54 -07:00
|
|
|
}
|
|
|
|
|
2013-02-01 19:43:17 -08:00
|
|
|
pub fn main() {
|
2015-01-25 22:05:03 +01:00
|
|
|
let x = 3;
|
2021-08-25 02:39:40 +02:00
|
|
|
let y = repeater(Box::new(x));
|
2013-07-18 17:12:46 -07:00
|
|
|
assert_eq!(x, y.get());
|
2013-02-14 11:47:00 -08:00
|
|
|
}
|