2018-08-30 12:18:55 +00:00
|
|
|
//@ run-pass
|
2018-09-25 21:51:35 +00:00
|
|
|
#![allow(dead_code)]
|
2015-03-22 20:13:15 +00:00
|
|
|
|
2012-10-13 00:00:08 +00:00
|
|
|
trait Deserializer {
|
2015-03-26 00:06:52 +00:00
|
|
|
fn read_int(&self) -> isize;
|
2012-10-13 00:00:08 +00:00
|
|
|
}
|
|
|
|
|
2013-02-21 01:07:17 +00:00
|
|
|
trait Deserializable<D:Deserializer> {
|
2013-03-22 02:07:54 +00:00
|
|
|
fn deserialize(d: &D) -> Self;
|
2012-10-13 00:00:08 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
impl<D:Deserializer> Deserializable<D> for isize {
|
|
|
|
fn deserialize(d: &D) -> isize {
|
2012-10-13 00:00:08 +00:00
|
|
|
return d.read_int();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct FromThinAir { dummy: () }
|
|
|
|
|
2013-02-14 19:47:00 +00:00
|
|
|
impl Deserializer for FromThinAir {
|
2015-03-26 00:06:52 +00:00
|
|
|
fn read_int(&self) -> isize { 22 }
|
2012-10-13 00:00:08 +00:00
|
|
|
}
|
|
|
|
|
2013-02-02 03:43:17 +00:00
|
|
|
pub fn main() {
|
2012-10-13 00:00:08 +00:00
|
|
|
let d = FromThinAir { dummy: () };
|
2015-03-26 00:06:52 +00:00
|
|
|
let i: isize = Deserializable::deserialize(&d);
|
2013-05-19 02:02:45 +00:00
|
|
|
assert_eq!(i, 22);
|
2013-01-31 03:42:06 +00:00
|
|
|
}
|