Fix serde build.
This commit is contained in:
parent
e306a92ea0
commit
3a6e6848fd
@ -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);
|
||||
|
@ -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>().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<Item = &'a Dynamic>> SeqAccess<'de> for Iterat
|
||||
/// `MapAccess` implementation for maps.
|
||||
struct IterateMap<'a, KEYS, VALUES>
|
||||
where
|
||||
KEYS: Iterator<Item = &'a ImmutableString>,
|
||||
KEYS: Iterator<Item = &'a str>,
|
||||
VALUES: Iterator<Item = &'a Dynamic>,
|
||||
{
|
||||
// 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<Item = &'a ImmutableString>,
|
||||
KEYS: Iterator<Item = &'a str>,
|
||||
VALUES: Iterator<Item = &'a Dynamic>,
|
||||
{
|
||||
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<Item = &'a ImmutableString>,
|
||||
KEYS: Iterator<Item = &'a str>,
|
||||
VALUES: Iterator<Item = &'a Dynamic>,
|
||||
{
|
||||
type Error = Box<EvalAltResult>;
|
||||
@ -543,11 +548,11 @@ where
|
||||
&mut self,
|
||||
seed: K,
|
||||
) -> Result<Option<K::Value>, Box<EvalAltResult>> {
|
||||
// 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),
|
||||
}
|
||||
}
|
||||
|
@ -143,8 +143,8 @@ impl<'d> Visitor<'d> for DynamicVisitor {
|
||||
fn visit_map<M: MapAccess<'d>>(self, mut map: M) -> Result<Self::Value, M::Error> {
|
||||
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())
|
||||
|
@ -550,7 +550,7 @@ impl SerializeMap for DynamicSerializer {
|
||||
})?;
|
||||
let _value = _value.serialize(&mut *self)?;
|
||||
let map = self._value.downcast_mut::<Map>().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::<Map>().unwrap();
|
||||
map.insert(_key, _value);
|
||||
map.insert(_key.into(), _value);
|
||||
Ok(())
|
||||
}
|
||||
#[cfg(feature = "no_object")]
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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<EvalAltResult>;
|
||||
|
||||
fn deserialize_any<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Box<EvalAltResult>> {
|
||||
@ -69,7 +69,7 @@ impl<'de> Deserializer<'de> for &mut ImmutableStringDeserializer<'de> {
|
||||
}
|
||||
fn deserialize_str<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Box<EvalAltResult>> {
|
||||
// Only allow deserialization into a string.
|
||||
v.visit_borrowed_str(self.value.as_str())
|
||||
v.visit_borrowed_str(self.value)
|
||||
}
|
||||
fn deserialize_string<V: Visitor<'de>>(
|
||||
self,
|
||||
|
Loading…
Reference in New Issue
Block a user