Fix builds.
This commit is contained in:
parent
27c0181035
commit
9a5bd9396a
@ -1,9 +1,8 @@
|
|||||||
//! Implement deserialization support of [`Dynamic`][crate::Dynamic] for [`serde`].
|
//! Implement deserialization support of [`Dynamic`][crate::Dynamic] for [`serde`].
|
||||||
|
|
||||||
use super::str::StringSliceDeserializer;
|
|
||||||
use crate::types::dynamic::Union;
|
use crate::types::dynamic::Union;
|
||||||
use crate::{Dynamic, EvalAltResult, ImmutableString, LexError, Position};
|
use crate::{Dynamic, EvalAltResult, ImmutableString, LexError, Position};
|
||||||
use serde::de::{DeserializeSeed, Error, IntoDeserializer, MapAccess, SeqAccess, Visitor};
|
use serde::de::{DeserializeSeed, Error, IntoDeserializer, Visitor};
|
||||||
use serde::{Deserialize, Deserializer};
|
use serde::{Deserialize, Deserializer};
|
||||||
#[cfg(feature = "no_std")]
|
#[cfg(feature = "no_std")]
|
||||||
use std::prelude::v1::*;
|
use std::prelude::v1::*;
|
||||||
@ -359,13 +358,14 @@ impl<'de> Deserializer<'de> for &mut DynamicDeserializer<'de> {
|
|||||||
|
|
||||||
fn deserialize_bytes<V: Visitor<'de>>(
|
fn deserialize_bytes<V: Visitor<'de>>(
|
||||||
self,
|
self,
|
||||||
visitor: V,
|
_visitor: V,
|
||||||
) -> Result<V::Value, Box<EvalAltResult>> {
|
) -> Result<V::Value, Box<EvalAltResult>> {
|
||||||
#[cfg(not(feature = "no_index"))]
|
#[cfg(not(feature = "no_index"))]
|
||||||
return self
|
return self
|
||||||
.value
|
.value
|
||||||
.downcast_ref::<Blob>()
|
.downcast_ref::<Blob>()
|
||||||
.map_or_else(|| self.type_error(), |x| visitor.visit_bytes(x));
|
.map_or_else(|| self.type_error(), |x| _visitor.visit_bytes(x));
|
||||||
|
|
||||||
#[cfg(feature = "no_index")]
|
#[cfg(feature = "no_index")]
|
||||||
return self.type_error();
|
return self.type_error();
|
||||||
}
|
}
|
||||||
@ -509,11 +509,13 @@ impl<'de> Deserializer<'de> for &mut DynamicDeserializer<'de> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// `SeqAccess` implementation for arrays.
|
/// `SeqAccess` implementation for arrays.
|
||||||
|
#[cfg(not(feature = "no_index"))]
|
||||||
struct IterateDynamicArray<'a, ITER: Iterator<Item = &'a Dynamic>> {
|
struct IterateDynamicArray<'a, ITER: Iterator<Item = &'a Dynamic>> {
|
||||||
/// Iterator for a stream of [`Dynamic`][crate::Dynamic] values.
|
/// Iterator for a stream of [`Dynamic`][crate::Dynamic] values.
|
||||||
iter: ITER,
|
iter: ITER,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "no_index"))]
|
||||||
impl<'a, ITER: Iterator<Item = &'a Dynamic>> IterateDynamicArray<'a, ITER> {
|
impl<'a, ITER: Iterator<Item = &'a Dynamic>> IterateDynamicArray<'a, ITER> {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn new(iter: ITER) -> Self {
|
pub fn new(iter: ITER) -> Self {
|
||||||
@ -521,7 +523,8 @@ impl<'a, ITER: Iterator<Item = &'a Dynamic>> IterateDynamicArray<'a, ITER> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a: 'de, 'de, ITER: Iterator<Item = &'a Dynamic>> SeqAccess<'de>
|
#[cfg(not(feature = "no_index"))]
|
||||||
|
impl<'a: 'de, 'de, ITER: Iterator<Item = &'a Dynamic>> serde::de::SeqAccess<'de>
|
||||||
for IterateDynamicArray<'a, ITER>
|
for IterateDynamicArray<'a, ITER>
|
||||||
{
|
{
|
||||||
type Error = Box<EvalAltResult>;
|
type Error = Box<EvalAltResult>;
|
||||||
@ -541,6 +544,7 @@ impl<'a: 'de, 'de, ITER: Iterator<Item = &'a Dynamic>> SeqAccess<'de>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// `MapAccess` implementation for maps.
|
/// `MapAccess` implementation for maps.
|
||||||
|
#[cfg(not(feature = "no_object"))]
|
||||||
struct IterateMap<'a, KEYS, VALUES>
|
struct IterateMap<'a, KEYS, VALUES>
|
||||||
where
|
where
|
||||||
KEYS: Iterator<Item = &'a str>,
|
KEYS: Iterator<Item = &'a str>,
|
||||||
@ -564,7 +568,8 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a: 'de, 'de, KEYS, VALUES> MapAccess<'de> for IterateMap<'a, KEYS, VALUES>
|
#[cfg(not(feature = "no_object"))]
|
||||||
|
impl<'a: 'de, 'de, KEYS, VALUES> serde::de::MapAccess<'de> for IterateMap<'a, KEYS, VALUES>
|
||||||
where
|
where
|
||||||
KEYS: Iterator<Item = &'a str>,
|
KEYS: Iterator<Item = &'a str>,
|
||||||
VALUES: Iterator<Item = &'a Dynamic>,
|
VALUES: Iterator<Item = &'a Dynamic>,
|
||||||
@ -579,7 +584,7 @@ where
|
|||||||
match self.keys.next() {
|
match self.keys.next() {
|
||||||
None => Ok(None),
|
None => Ok(None),
|
||||||
Some(item) => seed
|
Some(item) => seed
|
||||||
.deserialize(&mut StringSliceDeserializer::from_str(item))
|
.deserialize(&mut super::str::StringSliceDeserializer::from_str(item))
|
||||||
.map(Some),
|
.map(Some),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -260,8 +260,17 @@ impl Serializer for &mut DynamicSerializer {
|
|||||||
Ok(v.into())
|
Ok(v.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_bytes(self, v: &[u8]) -> Result<Self::Ok, Box<EvalAltResult>> {
|
fn serialize_bytes(self, _v: &[u8]) -> Result<Self::Ok, Box<EvalAltResult>> {
|
||||||
Ok(v.into())
|
#[cfg(not(feature = "no_index"))]
|
||||||
|
return Ok(Dynamic::from_blob(_v.to_vec()));
|
||||||
|
|
||||||
|
#[cfg(feature = "no_index")]
|
||||||
|
return Err(EvalAltResult::ErrorMismatchDataType(
|
||||||
|
"".into(),
|
||||||
|
"BLOB's are not supported with 'no_index'".into(),
|
||||||
|
Position::NONE,
|
||||||
|
)
|
||||||
|
.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_none(self) -> Result<Self::Ok, Box<EvalAltResult>> {
|
fn serialize_none(self) -> Result<Self::Ok, Box<EvalAltResult>> {
|
||||||
|
@ -2146,6 +2146,11 @@ impl Dynamic {
|
|||||||
}
|
}
|
||||||
#[cfg(not(feature = "no_index"))]
|
#[cfg(not(feature = "no_index"))]
|
||||||
impl Dynamic {
|
impl Dynamic {
|
||||||
|
/// Create a [`Dynamic`] from a [`Vec<u8>`].
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn from_blob(blob: Blob) -> Self {
|
||||||
|
Self(Union::Blob(Box::new(blob), DEFAULT_TAG_VALUE, ReadWrite))
|
||||||
|
}
|
||||||
/// Convert the [`Dynamic`] into a [`Vec<u8>`].
|
/// Convert the [`Dynamic`] into a [`Vec<u8>`].
|
||||||
/// Returns the name of the actual type if the cast fails.
|
/// Returns the name of the actual type if the cast fails.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
Loading…
Reference in New Issue
Block a user