SerializeState -> VisitorState

This commit is contained in:
Erick Tryzelaar
2014-09-01 13:39:54 -07:00
parent 4310645c7e
commit 01716fbdcf
2 changed files with 14 additions and 14 deletions
+2 -2
View File
@@ -12,7 +12,7 @@ struct Foo {
z: &'static str, z: &'static str,
} }
impl<S: serde2::SerializeState<R>, R> serde2::Serialize<S, R> for Foo { impl<S: serde2::VisitorState<R>, R> serde2::Serialize<S, R> for Foo {
fn serialize(&self, state: &mut S) -> R { fn serialize(&self, state: &mut S) -> R {
state.serialize_struct("Foo", FooSerialize { state.serialize_struct("Foo", FooSerialize {
value: self, value: self,
@@ -26,7 +26,7 @@ struct FooSerialize<'a> {
state: uint, state: uint,
} }
impl<'a, S: serde2::SerializeState<R>, R> serde2::Visitor<S, R> for FooSerialize<'a> { impl<'a, S: serde2::VisitorState<R>, R> serde2::Visitor<S, R> for FooSerialize<'a> {
fn visit(&mut self, state: &mut S) -> Option<R> { fn visit(&mut self, state: &mut S) -> Option<R> {
match self.state { match self.state {
0 => { 0 => {
+12 -12
View File
@@ -24,7 +24,7 @@ pub trait Visitor<S, R> {
} }
} }
pub trait SerializeState<R> { pub trait VisitorState<R> {
fn serialize_int(&mut self, value: int) -> R; fn serialize_int(&mut self, value: int) -> R;
fn serialize_str(&mut self, value: &'static str) -> R; fn serialize_str(&mut self, value: &'static str) -> R;
@@ -68,20 +68,20 @@ pub trait SerializeState<R> {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
impl<S: SerializeState<R>, R> Serialize<S, R> for int { impl<S: VisitorState<R>, R> Serialize<S, R> for int {
fn serialize(&self, state: &mut S) -> R { fn serialize(&self, state: &mut S) -> R {
state.serialize_int(*self) state.serialize_int(*self)
} }
} }
impl<S: SerializeState<R>, R> Serialize<S, R> for &'static str { impl<S: VisitorState<R>, R> Serialize<S, R> for &'static str {
fn serialize(&self, state: &mut S) -> R { fn serialize(&self, state: &mut S) -> R {
state.serialize_str(*self) state.serialize_str(*self)
} }
} }
impl< impl<
S: SerializeState<R>, S: VisitorState<R>,
R, R,
T: Serialize<S, R> T: Serialize<S, R>
> Serialize<S, R> for Vec<T> { > Serialize<S, R> for Vec<T> {
@@ -91,7 +91,7 @@ impl<
} }
impl< impl<
S: SerializeState<R>, S: VisitorState<R>,
R, R,
K: Serialize<S, R> + Ord, K: Serialize<S, R> + Ord,
V: Serialize<S, R> V: Serialize<S, R>
@@ -103,7 +103,7 @@ impl<
impl< impl<
'a, 'a,
S: SerializeState<R>, S: VisitorState<R>,
R, R,
T0: Serialize<S, R>, T0: Serialize<S, R>,
T1: Serialize<S, R> T1: Serialize<S, R>
@@ -120,7 +120,7 @@ struct Tuple2Serialize<'a, T0, T1> {
impl< impl<
'a, 'a,
S: SerializeState<R>, S: VisitorState<R>,
R, R,
T0: Serialize<S, R>, T0: Serialize<S, R>,
T1: Serialize<S, R> T1: Serialize<S, R>
@@ -151,7 +151,7 @@ impl<
impl< impl<
'a, 'a,
S: SerializeState<R>, S: VisitorState<R>,
R, R,
T: Serialize<S, R> T: Serialize<S, R>
> Serialize<S, R> for &'a T { > Serialize<S, R> for &'a T {
@@ -172,7 +172,7 @@ pub enum Token {
End, End,
} }
pub trait TokenState<R>: SerializeState<R> { pub trait TokenState<R>: VisitorState<R> {
fn serialize(&mut self, token: Token) -> R; fn serialize(&mut self, token: Token) -> R;
} }
@@ -200,7 +200,7 @@ impl TokenState<()> for GatherTokens {
} }
} }
impl SerializeState<()> for GatherTokens { impl VisitorState<()> for GatherTokens {
fn serialize_int(&mut self, value: int) -> () { fn serialize_int(&mut self, value: int) -> () {
self.serialize(Int(value)) self.serialize(Int(value))
} }
@@ -314,7 +314,7 @@ impl<W: Writer> FormatState<W> {
} }
} }
impl<W: Writer> SerializeState<IoResult<()>> for FormatState<W> { impl<W: Writer> VisitorState<IoResult<()>> for FormatState<W> {
fn serialize_int(&mut self, value: int) -> IoResult<()> { fn serialize_int(&mut self, value: int) -> IoResult<()> {
write!(self.writer, "{}", value) write!(self.writer, "{}", value)
} }
@@ -438,7 +438,7 @@ impl JsonSerializer {
} }
} }
impl SerializeState<Json> for JsonSerializer { impl VisitorState<Json> for JsonSerializer {
fn serialize_int(&mut self, value: int) -> Json { fn serialize_int(&mut self, value: int) -> Json {
Integer(value) Integer(value)
} }