2012-12-11 01:32:48 +00:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2015-03-06 02:33:58 +00:00
|
|
|
#![feature(core)]
|
|
|
|
|
2015-02-12 15:29:52 +00:00
|
|
|
use std::marker::MarkerTrait;
|
2013-10-23 08:49:18 +00:00
|
|
|
|
2015-02-12 15:29:52 +00:00
|
|
|
trait Serializer : MarkerTrait {
|
2012-09-10 19:25:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
trait Serializable {
|
2013-03-13 02:32:14 +00:00
|
|
|
fn serialize<S:Serializer>(&self, s: S);
|
2012-09-10 19:25:45 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 19:47:00 +00:00
|
|
|
impl Serializable for int {
|
2013-03-13 02:32:14 +00:00
|
|
|
fn serialize<S:Serializer>(&self, _s: S) { }
|
2012-09-10 19:25:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct F<A> { a: A }
|
|
|
|
|
2013-07-10 21:43:25 +00:00
|
|
|
impl<A:Serializable> Serializable for F<A> {
|
2013-03-13 02:32:14 +00:00
|
|
|
fn serialize<S:Serializer>(&self, s: S) {
|
2013-02-15 10:44:18 +00:00
|
|
|
self.a.serialize(s);
|
2012-09-10 19:25:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-14 01:48:47 +00:00
|
|
|
impl Serializer for int {
|
2012-09-10 19:25:45 +00:00
|
|
|
}
|
|
|
|
|
2013-02-02 03:43:17 +00:00
|
|
|
pub fn main() {
|
2015-01-25 21:05:03 +00:00
|
|
|
let foo = F { a: 1 };
|
|
|
|
foo.serialize(1);
|
2012-09-10 19:25:45 +00:00
|
|
|
|
2015-01-25 21:05:03 +00:00
|
|
|
let bar = F { a: F {a: 1 } };
|
|
|
|
bar.serialize(2);
|
2012-09-10 19:25:45 +00:00
|
|
|
}
|