mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-14 04:41:01 +00:00
Rename Serializer::new_with_formatter to with_formatter
This commit is contained in:
+18
-7
@@ -17,11 +17,20 @@ pub struct Serializer<W, F=CompactFormatter> {
|
|||||||
impl<W> Serializer<W>
|
impl<W> Serializer<W>
|
||||||
where W: io::Write,
|
where W: io::Write,
|
||||||
{
|
{
|
||||||
/// Creates a new JSON visitr whose output will be written to the writer
|
/// Creates a new JSON serializer.
|
||||||
/// specified.
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(writer: W) -> Serializer<W> {
|
pub fn new(writer: W) -> Serializer<W> {
|
||||||
Serializer::new_with_formatter(writer, CompactFormatter)
|
Serializer::with_formatter(writer, CompactFormatter)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<W> Serializer<W, PrettyFormatter<'static>>
|
||||||
|
where W: io::Write,
|
||||||
|
{
|
||||||
|
/// Creates a new JSON pretty print serializer.
|
||||||
|
#[inline]
|
||||||
|
pub fn pretty(writer: W) -> Serializer<W, PrettyFormatter<'static>> {
|
||||||
|
Serializer::with_formatter(writer, PrettyFormatter::new())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,10 +38,10 @@ impl<W, F> Serializer<W, F>
|
|||||||
where W: io::Write,
|
where W: io::Write,
|
||||||
F: Formatter,
|
F: Formatter,
|
||||||
{
|
{
|
||||||
/// Creates a new JSON visitr whose output will be written to the writer
|
/// Creates a new JSON visitor whose output will be written to the writer
|
||||||
/// specified.
|
/// specified.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new_with_formatter(writer: W, formatter: F) -> Serializer<W, F> {
|
pub fn with_formatter(writer: W, formatter: F) -> Serializer<W, F> {
|
||||||
Serializer {
|
Serializer {
|
||||||
writer: writer,
|
writer: writer,
|
||||||
formatter: formatter,
|
formatter: formatter,
|
||||||
@@ -300,11 +309,13 @@ pub struct PrettyFormatter<'a> {
|
|||||||
indent: &'a [u8],
|
indent: &'a [u8],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> PrettyFormatter<'a> {
|
impl PrettyFormatter<'static> {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
PrettyFormatter::with_indent(b" ")
|
PrettyFormatter::with_indent(b" ")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> PrettyFormatter<'a> {
|
||||||
fn with_indent(indent: &'a [u8]) -> Self {
|
fn with_indent(indent: &'a [u8]) -> Self {
|
||||||
PrettyFormatter {
|
PrettyFormatter {
|
||||||
current_indent: 0,
|
current_indent: 0,
|
||||||
@@ -452,7 +463,7 @@ pub fn to_writer_pretty<W, T>(writer: &mut W, value: &T) -> io::Result<()>
|
|||||||
where W: io::Write,
|
where W: io::Write,
|
||||||
T: ser::Serialize,
|
T: ser::Serialize,
|
||||||
{
|
{
|
||||||
let mut ser = Serializer::new_with_formatter(writer, PrettyFormatter::new());
|
let mut ser = Serializer::pretty(writer);
|
||||||
try!(value.serialize(&mut ser));
|
try!(value.serialize(&mut ser));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user