Skip to content

Commit

Permalink
ser: sequences: Centralise
Browse files Browse the repository at this point in the history
Have all the various versions of sequences (arrays and various forms
of tuple) all go via ser::SerializeSeq.

This reduces some duplication.  And, we're about to change the
implementation.

Signed-off-by: Ian Jackson <[email protected]>
  • Loading branch information
ijackson committed Oct 23, 2023
1 parent e95b9dd commit ed6a3c9
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,10 @@ impl<'a> ser::Serializer for &'a mut ConfigSerializer {
_name: &'static str,
_variant_index: u32,
variant: &'static str,
_len: usize,
len: usize,
) -> Result<Self::SerializeTupleVariant> {
self.push_key(variant);
Ok(self)
self.serialize_seq(Some(len))
}

fn serialize_map(self, _len: Option<usize>) -> Result<Self::SerializeMap> {
Expand Down Expand Up @@ -286,13 +286,11 @@ impl<'a> ser::SerializeTuple for &'a mut ConfigSerializer {
where
T: ?Sized + ser::Serialize,
{
self.inc_last_key_index()?;
value.serialize(&mut **self)?;
Ok(())
ser::SerializeSeq::serialize_element(self, value)
}

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

Expand All @@ -304,13 +302,11 @@ impl<'a> ser::SerializeTupleStruct for &'a mut ConfigSerializer {
where
T: ?Sized + ser::Serialize,
{
self.inc_last_key_index()?;
value.serialize(&mut **self)?;
Ok(())
ser::SerializeSeq::serialize_element(self, value)
}

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

Expand All @@ -322,12 +318,11 @@ impl<'a> ser::SerializeTupleVariant for &'a mut ConfigSerializer {
where
T: ?Sized + ser::Serialize,
{
self.inc_last_key_index()?;
value.serialize(&mut **self)?;
Ok(())
ser::SerializeSeq::serialize_element(self, value)
}

fn end(self) -> Result<Self::Ok> {
ser::SerializeSeq::end(&mut *self)?;
self.pop_key();
Ok(())
}
Expand Down

0 comments on commit ed6a3c9

Please sign in to comment.