Skip to content

Commit 6e0856f

Browse files
Rémi Labeyriedralley
Rémi Labeyrie
authored andcommitted
change return type of write_serializable_content
1 parent 79ff317 commit 6e0856f

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/errors.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ pub enum Error {
4343
EscapeError(EscapeError),
4444
/// Specified namespace prefix is unknown, cannot resolve namespace for it
4545
UnknownPrefix(Vec<u8>),
46-
/// Serialization error
47-
NonSerializable(String),
4846
}
4947

5048
impl From<IoError> for Error {
@@ -118,7 +116,6 @@ impl fmt::Display for Error {
118116
write_byte_string(f, prefix)?;
119117
f.write_str("'")
120118
}
121-
Error::NonSerializable(e) => write!(f, "error while serializing value: {e}"),
122119
}
123120
}
124121
}

src/writer.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
33
use std::io::Write;
44

5-
#[cfg(feature = "serialize")]
6-
use serde::Serialize;
7-
85
use crate::encoding::UTF8_BOM;
96
use crate::errors::Result;
107
use crate::events::{attributes::Attribute, BytesCData, BytesStart, BytesText, Event};
@@ -13,6 +10,10 @@ use crate::events::{attributes::Attribute, BytesCData, BytesStart, BytesText, Ev
1310
mod async_tokio;
1411

1512
/// XML writer. Writes XML [`Event`]s to a [`std::io::Write`] or [`tokio::io::AsyncWrite`] implementor.
13+
#[cfg(feature = "serialize")]
14+
use {crate::de::DeError, serde::Serialize};
15+
16+
/// XML writer. Writes XML [`Event`]s to a [`std::io::Write`] implementor.
1617
///
1718
/// # Examples
1819
///
@@ -346,7 +347,10 @@ impl<'a, W: Write> ElementWriter<'a, W> {
346347

347348
/// Serialize an arbitrary value inside the current element
348349
#[cfg(feature = "serialize")]
349-
pub fn write_serializable_content<T: Serialize>(self, content: T) -> Result<&'a mut Writer<W>> {
350+
pub fn write_serializable_content<T: Serialize>(
351+
self,
352+
content: T,
353+
) -> std::result::Result<&'a mut Writer<W>, DeError> {
350354
use crate::se::Serializer;
351355

352356
self.writer
@@ -364,9 +368,7 @@ impl<'a, W: Write> ElementWriter<'a, W> {
364368
);
365369
}
366370

367-
if let Err(error) = content.serialize(serializer) {
368-
return Err(Error::NonSerializable(error.to_string()));
369-
}
371+
content.serialize(serializer)?;
370372

371373
self.writer
372374
.write_event(Event::End(self.start_tag.to_end()))?;

0 commit comments

Comments
 (0)