Skip to content

Commit 7c3ea8a

Browse files
Mingundralley
authored andcommitted
Do not return writer from serializer methods
1 parent 7f7ef5f commit 7c3ea8a

File tree

3 files changed

+31
-31
lines changed

3 files changed

+31
-31
lines changed

src/se/content.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ macro_rules! write_primitive {
1414
($method:ident ( $ty:ty )) => {
1515
#[inline]
1616
fn $method(self, value: $ty) -> Result<Self::Ok, Self::Error> {
17-
self.into_simple_type_serializer().$method(value)
17+
self.into_simple_type_serializer().$method(value)?;
18+
Ok(())
1819
}
1920
};
2021
}
@@ -89,16 +90,16 @@ impl<'i, W: Write> ContentSerializer<'i, W> {
8990

9091
/// Writes `name` as self-closed tag
9192
#[inline]
92-
pub(super) fn write_empty(mut self, name: XmlName) -> Result<W, DeError> {
93+
pub(super) fn write_empty(mut self, name: XmlName) -> Result<(), DeError> {
9394
self.write_indent()?;
9495
self.writer.write_char('<')?;
9596
self.writer.write_str(name.0)?;
9697
self.writer.write_str("/>")?;
97-
Ok(self.writer)
98+
Ok(())
9899
}
99100

100101
/// Writes simple type content between `name` tags
101-
pub(super) fn write_wrapped<S>(mut self, name: XmlName, serialize: S) -> Result<W, DeError>
102+
pub(super) fn write_wrapped<S>(mut self, name: XmlName, serialize: S) -> Result<(), DeError>
102103
where
103104
S: FnOnce(SimpleTypeSerializer<'i, W>) -> Result<W, DeError>,
104105
{
@@ -112,7 +113,7 @@ impl<'i, W: Write> ContentSerializer<'i, W> {
112113
writer.write_str("</")?;
113114
writer.write_str(name.0)?;
114115
writer.write_char('>')?;
115-
Ok(writer)
116+
Ok(())
116117
}
117118

118119
pub(super) fn write_indent(&mut self) -> Result<(), DeError> {
@@ -125,7 +126,7 @@ impl<'i, W: Write> ContentSerializer<'i, W> {
125126
}
126127

127128
impl<'i, W: Write> Serializer for ContentSerializer<'i, W> {
128-
type Ok = W;
129+
type Ok = ();
129130
type Error = DeError;
130131

131132
type SerializeSeq = Self;
@@ -161,17 +162,16 @@ impl<'i, W: Write> Serializer for ContentSerializer<'i, W> {
161162

162163
#[inline]
163164
fn serialize_str(self, value: &str) -> Result<Self::Ok, Self::Error> {
164-
if value.is_empty() {
165-
Ok(self.writer)
166-
} else {
167-
self.into_simple_type_serializer().serialize_str(value)
165+
if !value.is_empty() {
166+
self.into_simple_type_serializer().serialize_str(value)?;
168167
}
168+
Ok(())
169169
}
170170

171171
/// Does not write anything
172172
#[inline]
173173
fn serialize_none(self) -> Result<Self::Ok, Self::Error> {
174-
Ok(self.writer)
174+
Ok(())
175175
}
176176

177177
fn serialize_some<T: ?Sized + Serialize>(self, value: &T) -> Result<Self::Ok, Self::Error> {
@@ -181,13 +181,13 @@ impl<'i, W: Write> Serializer for ContentSerializer<'i, W> {
181181
/// Does not write anything
182182
#[inline]
183183
fn serialize_unit(self) -> Result<Self::Ok, Self::Error> {
184-
Ok(self.writer)
184+
Ok(())
185185
}
186186

187187
/// Does not write anything
188188
#[inline]
189189
fn serialize_unit_struct(self, _name: &'static str) -> Result<Self::Ok, Self::Error> {
190-
Ok(self.writer)
190+
Ok(())
191191
}
192192

193193
/// Checks `variant` for XML name validity and writes `<${variant}/>`
@@ -298,7 +298,7 @@ impl<'i, W: Write> Serializer for ContentSerializer<'i, W> {
298298
}
299299

300300
impl<'i, W: Write> SerializeSeq for ContentSerializer<'i, W> {
301-
type Ok = W;
301+
type Ok = ();
302302
type Error = DeError;
303303

304304
fn serialize_element<T>(&mut self, value: &T) -> Result<(), Self::Error>
@@ -313,12 +313,12 @@ impl<'i, W: Write> SerializeSeq for ContentSerializer<'i, W> {
313313

314314
#[inline]
315315
fn end(self) -> Result<Self::Ok, Self::Error> {
316-
Ok(self.writer)
316+
Ok(())
317317
}
318318
}
319319

320320
impl<'i, W: Write> SerializeTuple for ContentSerializer<'i, W> {
321-
type Ok = W;
321+
type Ok = ();
322322
type Error = DeError;
323323

324324
#[inline]
@@ -336,7 +336,7 @@ impl<'i, W: Write> SerializeTuple for ContentSerializer<'i, W> {
336336
}
337337

338338
impl<'i, W: Write> SerializeTupleStruct for ContentSerializer<'i, W> {
339-
type Ok = W;
339+
type Ok = ();
340340
type Error = DeError;
341341

342342
#[inline]

src/se/element.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub struct ElementSerializer<'k, W: Write> {
3131
}
3232

3333
impl<'k, W: Write> Serializer for ElementSerializer<'k, W> {
34-
type Ok = W;
34+
type Ok = ();
3535
type Error = DeError;
3636

3737
type SerializeSeq = Self;
@@ -201,7 +201,7 @@ impl<'k, W: Write> Serializer for ElementSerializer<'k, W> {
201201
}
202202

203203
impl<'k, W: Write> SerializeSeq for ElementSerializer<'k, W> {
204-
type Ok = W;
204+
type Ok = ();
205205
type Error = DeError;
206206

207207
fn serialize_element<T>(&mut self, value: &T) -> Result<(), Self::Error>
@@ -219,12 +219,12 @@ impl<'k, W: Write> SerializeSeq for ElementSerializer<'k, W> {
219219

220220
#[inline]
221221
fn end(self) -> Result<Self::Ok, Self::Error> {
222-
Ok(self.ser.writer)
222+
Ok(())
223223
}
224224
}
225225

226226
impl<'k, W: Write> SerializeTuple for ElementSerializer<'k, W> {
227-
type Ok = W;
227+
type Ok = ();
228228
type Error = DeError;
229229

230230
#[inline]
@@ -242,7 +242,7 @@ impl<'k, W: Write> SerializeTuple for ElementSerializer<'k, W> {
242242
}
243243

244244
impl<'k, W: Write> SerializeTupleStruct for ElementSerializer<'k, W> {
245-
type Ok = W;
245+
type Ok = ();
246246
type Error = DeError;
247247

248248
#[inline]
@@ -260,7 +260,7 @@ impl<'k, W: Write> SerializeTupleStruct for ElementSerializer<'k, W> {
260260
}
261261

262262
impl<'k, W: Write> SerializeTupleVariant for ElementSerializer<'k, W> {
263-
type Ok = W;
263+
type Ok = ();
264264
type Error = DeError;
265265

266266
#[inline]
@@ -371,7 +371,7 @@ impl<'k, W: Write> Struct<'k, W> {
371371
}
372372

373373
impl<'k, W: Write> SerializeStruct for Struct<'k, W> {
374-
type Ok = W;
374+
type Ok = ();
375375
type Error = DeError;
376376

377377
fn serialize_field<T>(&mut self, key: &'static str, value: &T) -> Result<(), Self::Error>
@@ -396,12 +396,12 @@ impl<'k, W: Write> SerializeStruct for Struct<'k, W> {
396396
self.ser.ser.writer.write_str(self.ser.key.0)?;
397397
self.ser.ser.writer.write_char('>')?;
398398
}
399-
Ok(self.ser.ser.writer)
399+
Ok(())
400400
}
401401
}
402402

403403
impl<'k, W: Write> SerializeStructVariant for Struct<'k, W> {
404-
type Ok = W;
404+
type Ok = ();
405405
type Error = DeError;
406406

407407
#[inline]
@@ -439,7 +439,7 @@ impl<'k, W: Write> Map<'k, W> {
439439
}
440440

441441
impl<'k, W: Write> SerializeMap for Map<'k, W> {
442-
type Ok = W;
442+
type Ok = ();
443443
type Error = DeError;
444444

445445
fn serialize_key<T>(&mut self, key: &T) -> Result<(), Self::Error>

src/se/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ use std::str::from_utf8;
122122
/// </Root>"
123123
/// );
124124
/// ```
125-
pub fn to_writer<W, T>(writer: W, value: &T) -> Result<W, DeError>
125+
pub fn to_writer<W, T>(writer: W, value: &T) -> Result<(), DeError>
126126
where
127127
W: Write,
128128
T: ?Sized + Serialize,
@@ -208,7 +208,7 @@ where
208208
/// ```
209209
///
210210
/// [XML name]: https://www.w3.org/TR/REC-xml/#NT-Name
211-
pub fn to_writer_with_root<W, T>(writer: W, root_tag: &str, value: &T) -> Result<W, DeError>
211+
pub fn to_writer_with_root<W, T>(writer: W, root_tag: &str, value: &T) -> Result<(), DeError>
212212
where
213213
W: Write,
214214
T: ?Sized + Serialize,
@@ -560,7 +560,7 @@ impl<'r, W: Write> Serializer<'r, W> {
560560
}
561561

562562
impl<'r, W: Write> ser::Serializer for Serializer<'r, W> {
563-
type Ok = W;
563+
type Ok = ();
564564
type Error = DeError;
565565

566566
type SerializeSeq = <ElementSerializer<'r, W> as ser::Serializer>::SerializeSeq;
@@ -598,7 +598,7 @@ impl<'r, W: Write> ser::Serializer for Serializer<'r, W> {
598598
forward!(serialize_bytes(&[u8]));
599599

600600
fn serialize_none(self) -> Result<Self::Ok, DeError> {
601-
Ok(self.ser.writer)
601+
Ok(())
602602
}
603603

604604
fn serialize_some<T: ?Sized + Serialize>(self, value: &T) -> Result<Self::Ok, DeError> {

0 commit comments

Comments
 (0)