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