Skip to content

Commit

Permalink
deserialize tuples
Browse files Browse the repository at this point in the history
all deserialization functions are now implemented
  • Loading branch information
lovasoa committed Apr 8, 2024
1 parent 3d1bfa5 commit 9488654
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,23 +492,23 @@ impl<'de, 'a, R: Read> de::Deserializer<'de> for &'a mut Deserializer<R> {
visitor.visit_seq(&mut seq_deser)
}

fn deserialize_tuple<V>(self, _len: usize, _visitor: V) -> Result<V::Value>
fn deserialize_tuple<V>(self, _len: usize, visitor: V) -> Result<V::Value>
where
V: Visitor<'de>,
{
todo!()
self.deserialize_seq(visitor)
}

fn deserialize_tuple_struct<V>(
self,
_name: &'static str,
_len: usize,
_visitor: V,
visitor: V,
) -> Result<V::Value>
where
V: Visitor<'de>,
{
todo!()
self.deserialize_seq(visitor)
}

fn deserialize_map<V>(self, visitor: V) -> Result<V::Value>
Expand Down Expand Up @@ -868,6 +868,24 @@ mod tests {
assert_eq!(from_bytes::<String>(b"\x49\\x0A").unwrap(), "\n");
}

#[test]
fn test_tuple() {
assert_eq!(
from_bytes::<(u8, i64, char)>(b"\x6b\x131\x132\x18x").unwrap(),
(1, 2, 'x')
);
}

#[test]
fn test_tuple_struct() {
#[derive(Debug, PartialEq, serde_derive::Deserialize)]
struct Test(Option<String>, bool, bool);
assert_eq!(
from_bytes::<Test>(b"\x3b\x00\x01\x02").unwrap(),
Test(None, true, false)
);
}

#[test]
fn test_vec() {
assert_eq!(from_bytes::<Vec<()>>(b"\x0b").unwrap(), vec![]);
Expand Down

0 comments on commit 9488654

Please sign in to comment.