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