2014-02-20 02:56:33 +00:00
|
|
|
use std::fmt;
|
|
|
|
|
2014-01-13 00:59:47 +00:00
|
|
|
struct Number {
|
|
|
|
n: i64
|
|
|
|
}
|
|
|
|
|
2015-02-21 11:28:28 +00:00
|
|
|
impl fmt::Display for Number {
|
2014-02-20 02:56:33 +00:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2014-05-10 21:05:06 +00:00
|
|
|
write!(f, "{}", self.n)
|
2014-01-13 00:59:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct List {
|
2019-05-28 18:46:13 +00:00
|
|
|
list: Vec<Box<dyn ToString + 'static>> }
|
2014-01-13 00:59:47 +00:00
|
|
|
|
|
|
|
impl List {
|
2019-05-28 18:46:13 +00:00
|
|
|
fn push(&mut self, n: Box<dyn ToString + 'static>) {
|
2014-01-13 00:59:47 +00:00
|
|
|
self.list.push(n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2021-08-25 00:39:40 +00:00
|
|
|
|
|
|
|
let n: Box<_> = Number { n: 42 }.into();
|
|
|
|
let mut l: Box<_> = List { list: Vec::new() }.into();
|
2014-01-13 00:59:47 +00:00
|
|
|
l.push(n);
|
2021-08-25 00:39:40 +00:00
|
|
|
|
2014-06-21 10:39:03 +00:00
|
|
|
let x = n.to_string();
|
2019-04-22 07:40:08 +00:00
|
|
|
//~^ ERROR: borrow of moved value: `n`
|
2014-01-13 00:59:47 +00:00
|
|
|
}
|