Skip to content

Commit

Permalink
Moved Seq to /src/ser/seq.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-F-Bryan committed Aug 22, 2017
1 parent a19ec90 commit 023698a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 22 deletions.
26 changes: 4 additions & 22 deletions src/ser/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use std::io::Write;
use std::fmt::Display;

use serde::ser::{self, Impossible, Serialize, SerializeSeq};
use serde::ser::{self, Impossible, Serialize};

use error::{Error, ErrorKind, Result};
use self::var::{Map, Struct};
use self::seq::Seq;

mod var;
mod seq;


/// A convenience method for serializing some object to a buffer.
Expand Down Expand Up @@ -234,7 +236,7 @@ where
}

fn serialize_seq(self, len: Option<usize>) -> Result<Self::SerializeSeq> {
Ok(Seq { parent: self })
Ok(Seq::new(self))
}

fn serialize_tuple(self, len: usize) -> Result<Self::SerializeTuple> {
Expand Down Expand Up @@ -285,26 +287,6 @@ where
}
}

pub struct Seq<'a, W: 'a + Write> {
parent: &'a mut Serializer<W>,
}

impl<'a, W: Write> SerializeSeq for Seq<'a, W> {
type Ok = ();
type Error = Error;

fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<Self::Ok>
where
T: Serialize,
{
value.serialize(&mut *self.parent)
}

fn end(self) -> Result<Self::Ok> {
Ok(())
}
}


#[cfg(test)]
mod tests {
Expand Down
35 changes: 35 additions & 0 deletions src/ser/seq.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use std::io::Write;
use serde::ser::{Serialize, SerializeSeq};

use ser::Serializer;
use error::{Error, Result};

pub struct Seq<'a, W: 'a + Write> {
parent: &'a mut Serializer<W>,
}


impl<'w, W> Seq<'w, W>
where
W: 'w + Write,
{
pub fn new(parent: &'w mut Serializer<W>) -> Seq<'w, W> {
Seq { parent }
}
}

impl<'a, W: Write> SerializeSeq for Seq<'a, W> {
type Ok = ();
type Error = Error;

fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<Self::Ok>
where
T: Serialize,
{
value.serialize(&mut *self.parent)
}

fn end(self) -> Result<Self::Ok> {
Ok(())
}
}

0 comments on commit 023698a

Please sign in to comment.