remove lifetime parameter on serializer
This commit is contained in:
parent
c3aaeaa6f6
commit
ae8021f79a
@ -23,7 +23,7 @@ pub trait YaDeserialize: Sized {
|
||||
}
|
||||
|
||||
/// A **data structure** that can be serialized into any data format supported by YaSerDe.
|
||||
pub trait YaSerialize<'a>: Sized {
|
||||
pub trait YaSerialize: Sized {
|
||||
fn serialize<W: Write>(&self, writer: &mut ser::Serializer<W>) -> Result<(), String>;
|
||||
|
||||
fn serialize_attributes(
|
||||
@ -95,7 +95,7 @@ pub trait Visitor<'de>: Sized {
|
||||
|
||||
macro_rules! serialize_type {
|
||||
($type:ty) => {
|
||||
impl<'a> YaSerialize<'a> for $type {
|
||||
impl YaSerialize for $type {
|
||||
fn serialize<W: Write>(&self, writer: &mut ser::Serializer<W>) -> Result<(), String> {
|
||||
let content = format!("{}", self);
|
||||
let event = XmlEvent::characters(&content);
|
||||
|
@ -7,24 +7,21 @@ use std::str;
|
||||
use xml::writer::XmlEvent;
|
||||
use xml::{EmitterConfig, EventWriter};
|
||||
|
||||
pub fn to_string<'a, T: YaSerialize<'a>>(model: &T) -> Result<String, String> {
|
||||
pub fn to_string<T: YaSerialize>(model: &T) -> Result<String, String> {
|
||||
let buf = Cursor::new(Vec::new());
|
||||
let cursor = serialize_with_writer(model, buf, &Config::default())?;
|
||||
let data = str::from_utf8(cursor.get_ref()).expect("Found invalid UTF-8");
|
||||
Ok(String::from(data))
|
||||
}
|
||||
|
||||
pub fn to_string_with_config<'a, T: YaSerialize<'a>>(
|
||||
model: &T,
|
||||
config: &Config,
|
||||
) -> Result<String, String> {
|
||||
pub fn to_string_with_config<T: YaSerialize>(model: &T, config: &Config) -> Result<String, String> {
|
||||
let buf = Cursor::new(Vec::new());
|
||||
let cursor = serialize_with_writer(model, buf, config)?;
|
||||
let data = str::from_utf8(cursor.get_ref()).expect("Found invalid UTF-8");
|
||||
Ok(String::from(data))
|
||||
}
|
||||
|
||||
pub fn serialize_with_writer<'a, W: Write, T: YaSerialize<'a>>(
|
||||
pub fn serialize_with_writer<W: Write, T: YaSerialize>(
|
||||
model: &T,
|
||||
writer: W,
|
||||
_config: &Config,
|
||||
@ -36,14 +33,14 @@ pub fn serialize_with_writer<'a, W: Write, T: YaSerialize<'a>>(
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_string_content<'a, T: YaSerialize<'a>>(model: &T) -> Result<String, String> {
|
||||
pub fn to_string_content<T: YaSerialize>(model: &T) -> Result<String, String> {
|
||||
let buf = Cursor::new(Vec::new());
|
||||
let cursor = serialize_with_writer_content(model, buf)?;
|
||||
let data = str::from_utf8(cursor.get_ref()).expect("Found invalid UTF-8");
|
||||
Ok(String::from(data))
|
||||
}
|
||||
|
||||
pub fn serialize_with_writer_content<'a, W: Write, T: YaSerialize<'a>>(
|
||||
pub fn serialize_with_writer_content<W: Write, T: YaSerialize>(
|
||||
model: &T,
|
||||
writer: W,
|
||||
) -> Result<W, String> {
|
||||
|
@ -293,7 +293,7 @@ fn ser_custom() {
|
||||
value: i32,
|
||||
}
|
||||
|
||||
impl<'a> YaSerialize<'a> for Day {
|
||||
impl YaSerialize for Day {
|
||||
fn serialize<W: Write>(&self, writer: &mut yaserde::ser::Serializer<W>) -> Result<(), String> {
|
||||
let _ret = writer.write(xml::writer::XmlEvent::start_element("DoubleDay"));
|
||||
let _ret = writer.write(xml::writer::XmlEvent::characters(
|
||||
|
@ -16,7 +16,7 @@ pub fn implement_serializer(
|
||||
quote! {
|
||||
use xml::writer::XmlEvent;
|
||||
|
||||
impl<'a> YaSerialize<'a> for #name {
|
||||
impl YaSerialize for #name {
|
||||
#[allow(unused_variables)]
|
||||
fn serialize<W: Write>(&self, writer: &mut yaserde::ser::Serializer<W>)
|
||||
-> Result<(), String> {
|
||||
|
Loading…
Reference in New Issue
Block a user