From 3a6e6848fd2ba02bd8110919abb73f852912f87f Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Mon, 29 Mar 2021 18:46:32 +0800 Subject: [PATCH] Fix serde build. --- src/module/mod.rs | 4 ++-- src/serde/de.rs | 19 ++++++++++++------- src/serde/deserialize.rs | 4 ++-- src/serde/ser.rs | 4 ++-- src/serde/serialize.rs | 2 +- src/serde/str.rs | 16 ++++++++-------- 6 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/module/mod.rs b/src/module/mod.rs index 320307be..824d4e72 100644 --- a/src/module/mod.rs +++ b/src/module/mod.rs @@ -622,7 +622,7 @@ impl Module { pub fn update_fn_metadata(&mut self, hash_fn: u64, arg_names: &[&str]) -> &mut Self { let param_names = arg_names .iter() - .map(|&name| self.interned_strings.get(name)) + .map(|&name| self.identifiers.get(name)) .collect(); if let Some(f) = self.functions.get_mut(&hash_fn) { @@ -692,7 +692,7 @@ impl Module { let param_names = _arg_names .iter() .flat_map(|p| p.iter()) - .map(|&arg| self.interned_strings.get(arg)) + .map(|&arg| self.identifiers.get(arg)) .collect(); let hash_fn = calc_native_fn_hash(empty(), &name, ¶m_types); diff --git a/src/serde/de.rs b/src/serde/de.rs index 2d9adafa..802a47e2 100644 --- a/src/serde/de.rs +++ b/src/serde/de.rs @@ -1,6 +1,6 @@ //! Implement deserialization support of [`Dynamic`][crate::Dynamic] for [`serde`]. -use super::str::ImmutableStringDeserializer; +use super::str::StringSliceDeserializer; use crate::dynamic::Union; use crate::stdlib::{any::type_name, boxed::Box, fmt, string::ToString}; use crate::{Dynamic, EvalAltResult, ImmutableString, LexError, Position}; @@ -418,7 +418,12 @@ impl<'de> Deserializer<'de> for &mut DynamicDeserializer<'de> { #[cfg(not(feature = "no_object"))] return self.value.downcast_ref::().map_or_else( || self.type_error(), - |map| _visitor.visit_map(IterateMap::new(map.keys(), map.values())), + |map| { + _visitor.visit_map(IterateMap::new( + map.keys().map(|key| key.as_str()), + map.values(), + )) + }, ); #[cfg(feature = "no_object")] @@ -512,7 +517,7 @@ impl<'a: 'de, 'de, ITER: Iterator> SeqAccess<'de> for Iterat /// `MapAccess` implementation for maps. struct IterateMap<'a, KEYS, VALUES> where - KEYS: Iterator, + KEYS: Iterator, VALUES: Iterator, { // Iterator for a stream of [`Dynamic`][crate::Dynamic] keys. @@ -524,7 +529,7 @@ where #[cfg(not(feature = "no_object"))] impl<'a, KEYS, VALUES> IterateMap<'a, KEYS, VALUES> where - KEYS: Iterator, + KEYS: Iterator, VALUES: Iterator, { pub fn new(keys: KEYS, values: VALUES) -> Self { @@ -534,7 +539,7 @@ where impl<'a: 'de, 'de, KEYS, VALUES> MapAccess<'de> for IterateMap<'a, KEYS, VALUES> where - KEYS: Iterator, + KEYS: Iterator, VALUES: Iterator, { type Error = Box; @@ -543,11 +548,11 @@ where &mut self, seed: K, ) -> Result, Box> { - // Deserialize each `ImmutableString` key coming out of the keys iterator. + // Deserialize each `Identifier` key coming out of the keys iterator. match self.keys.next() { None => Ok(None), Some(item) => seed - .deserialize(&mut ImmutableStringDeserializer::from_str(item)) + .deserialize(&mut StringSliceDeserializer::from_str(item)) .map(Some), } } diff --git a/src/serde/deserialize.rs b/src/serde/deserialize.rs index 224fe5e7..cd8c852a 100644 --- a/src/serde/deserialize.rs +++ b/src/serde/deserialize.rs @@ -143,8 +143,8 @@ impl<'d> Visitor<'d> for DynamicVisitor { fn visit_map>(self, mut map: M) -> Result { let mut m: Map = Default::default(); - while let Some((k, v)) = map.next_entry()? { - m.insert(k, v); + while let Some((k, v)) = map.next_entry::<&str, _>()? { + m.insert(k.into(), v); } Ok(m.into()) diff --git a/src/serde/ser.rs b/src/serde/ser.rs index 6b0d221e..73cab25c 100644 --- a/src/serde/ser.rs +++ b/src/serde/ser.rs @@ -550,7 +550,7 @@ impl SerializeMap for DynamicSerializer { })?; let _value = _value.serialize(&mut *self)?; let map = self._value.downcast_mut::().unwrap(); - map.insert(key, _value); + map.insert(key.into(), _value); Ok(()) } #[cfg(feature = "no_object")] @@ -575,7 +575,7 @@ impl SerializeMap for DynamicSerializer { })?; let _value = _value.serialize(&mut *self)?; let map = self._value.downcast_mut::().unwrap(); - map.insert(_key, _value); + map.insert(_key.into(), _value); Ok(()) } #[cfg(feature = "no_object")] diff --git a/src/serde/serialize.rs b/src/serde/serialize.rs index 05afd31b..2491b2f9 100644 --- a/src/serde/serialize.rs +++ b/src/serde/serialize.rs @@ -54,7 +54,7 @@ impl Serialize for Dynamic { Union::Map(m, _) => { let mut map = ser.serialize_map(Some(m.len()))?; for (k, v) in m.iter() { - map.serialize_entry(k, v)?; + map.serialize_entry(k.as_str(), v)?; } map.end() } diff --git a/src/serde/str.rs b/src/serde/str.rs index 6c14be25..ccc7a0a7 100644 --- a/src/serde/str.rs +++ b/src/serde/str.rs @@ -1,17 +1,17 @@ //! Implement deserialization support of [`ImmutableString`][crate::ImmutableString] for [`serde`]. use crate::stdlib::{any::type_name, boxed::Box}; -use crate::{EvalAltResult, ImmutableString, Position}; +use crate::{EvalAltResult, Position}; use serde::de::{Deserializer, Visitor}; /// Deserializer for `ImmutableString`. -pub struct ImmutableStringDeserializer<'a> { - value: &'a ImmutableString, +pub struct StringSliceDeserializer<'a> { + value: &'a str, } -impl<'a> ImmutableStringDeserializer<'a> { - /// Create an `ImmutableStringDeserializer` from an `ImmutableString` reference. - pub fn from_str(value: &'a ImmutableString) -> Self { +impl<'a> StringSliceDeserializer<'a> { + /// Create an `ImmutableStringDeserializer` from an `&str` reference. + pub fn from_str(value: &'a str) -> Self { Self { value } } /// Shortcut for a type conversion error. @@ -25,7 +25,7 @@ impl<'a> ImmutableStringDeserializer<'a> { } } -impl<'de> Deserializer<'de> for &mut ImmutableStringDeserializer<'de> { +impl<'de> Deserializer<'de> for &mut StringSliceDeserializer<'de> { type Error = Box; fn deserialize_any>(self, v: V) -> Result> { @@ -69,7 +69,7 @@ impl<'de> Deserializer<'de> for &mut ImmutableStringDeserializer<'de> { } fn deserialize_str>(self, v: V) -> Result> { // Only allow deserialization into a string. - v.visit_borrowed_str(self.value.as_str()) + v.visit_borrowed_str(self.value) } fn deserialize_string>( self,