Skip to content

Commit

Permalink
VariantDispatch passing all serde tests; remove Variant impls for now
Browse files Browse the repository at this point in the history
still needs cleanup
  • Loading branch information
Waridley committed Jun 16, 2021
1 parent 95e1ab0 commit 59b5384
Show file tree
Hide file tree
Showing 5 changed files with 988 additions and 953 deletions.
114 changes: 57 additions & 57 deletions gdnative-core/src/core_types/dictionary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,63 +577,63 @@ where
}
}

#[cfg(feature = "serde")]
pub(super) mod serde {
use super::*;
use ::serde::{
de::{MapAccess, Visitor},
ser::SerializeMap,
Deserialize, Deserializer, Serialize, Serializer,
};
use std::fmt::Formatter;

impl Serialize for Dictionary {
#[inline]
fn serialize<S>(&self, ser: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let mut ser = ser.serialize_map(Some(self.len() as usize))?;
for (key, value) in self.iter() {
ser.serialize_entry(&key, &value)?
}
ser.end()
}
}

pub(in super::super) struct DictionaryVisitor;

impl<'de> Visitor<'de> for DictionaryVisitor {
type Value = Dictionary<Unique>;

fn expecting(&self, formatter: &mut Formatter) -> fmt::Result {
formatter.write_str("a Dictionary")
}

fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error>
where
A: MapAccess<'de>,
{
let dict = Dictionary::new();
while let Some((key, value)) = map.next_entry::<Variant, Variant>()? {
dict.insert(key, value)
}
Ok(dict)
}
}

impl<'de, Access: ThreadAccess> Deserialize<'de> for Dictionary<Access> {
#[inline]
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
deserializer
.deserialize_map(DictionaryVisitor)
.map(|dict| unsafe { dict.cast_access() })
}
}
}
// #[cfg(feature = "serde")]
// pub(super) mod serde {
// use super::*;
// use ::serde::{
// de::{MapAccess, Visitor},
// ser::SerializeMap,
// Deserialize, Deserializer, Serialize, Serializer,
// };
// use std::fmt::Formatter;
//
// impl Serialize for Dictionary {
// #[inline]
// fn serialize<S>(&self, ser: S) -> Result<S::Ok, S::Error>
// where
// S: Serializer,
// {
// let mut ser = ser.serialize_map(Some(self.len() as usize))?;
// for (key, value) in self.iter() {
// ser.serialize_entry(&key, &value)?
// }
// ser.end()
// }
// }
//
// pub(in super::super) struct DictionaryVisitor;
//
// impl<'de> Visitor<'de> for DictionaryVisitor {
// type Value = Dictionary<Unique>;
//
// fn expecting(&self, formatter: &mut Formatter) -> fmt::Result {
// formatter.write_str("a Dictionary")
// }
//
// fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error>
// where
// A: MapAccess<'de>,
// {
// let dict = Dictionary::new();
// while let Some((key, value)) = map.next_entry::<Variant, Variant>()? {
// dict.insert(key, value)
// }
// Ok(dict)
// }
// }
//
// impl<'de, Access: ThreadAccess> Deserialize<'de> for Dictionary<Access> {
// #[inline]
// fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
// where
// D: Deserializer<'de>,
// {
// deserializer
// .deserialize_map(DictionaryVisitor)
// .map(|dict| unsafe { dict.cast_access() })
// }
// }
// }

godot_test!(test_dictionary {
use std::collections::HashSet;
Expand Down
Loading

0 comments on commit 59b5384

Please sign in to comment.