mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-13 04:21:04 +00:00
Allow using IgnoredAny as a visitor
This commit is contained in:
+99
-95
@@ -7,106 +7,110 @@ use de::{Deserialize, Deserializer, Visitor, SeqVisitor, MapVisitor, Error};
|
|||||||
#[derive(Copy, Clone, Debug, Default)]
|
#[derive(Copy, Clone, Debug, Default)]
|
||||||
pub struct IgnoredAny;
|
pub struct IgnoredAny;
|
||||||
|
|
||||||
|
impl<'de> Visitor<'de> for IgnoredAny {
|
||||||
|
type Value = IgnoredAny;
|
||||||
|
|
||||||
|
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
formatter.write_str("anything at all")
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn visit_bool<E>(self, x: bool) -> Result<Self::Value, E> {
|
||||||
|
let _ = x;
|
||||||
|
Ok(IgnoredAny)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn visit_i64<E>(self, x: i64) -> Result<Self::Value, E> {
|
||||||
|
let _ = x;
|
||||||
|
Ok(IgnoredAny)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn visit_u64<E>(self, x: u64) -> Result<Self::Value, E> {
|
||||||
|
let _ = x;
|
||||||
|
Ok(IgnoredAny)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn visit_f64<E>(self, x: f64) -> Result<Self::Value, E> {
|
||||||
|
let _ = x;
|
||||||
|
Ok(IgnoredAny)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn visit_str<E>(self, s: &str) -> Result<Self::Value, E>
|
||||||
|
where
|
||||||
|
E: Error,
|
||||||
|
{
|
||||||
|
let _ = s;
|
||||||
|
Ok(IgnoredAny)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn visit_none<E>(self) -> Result<Self::Value, E> {
|
||||||
|
Ok(IgnoredAny)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn visit_some<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
IgnoredAny::deserialize(deserializer)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn visit_newtype_struct<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
IgnoredAny::deserialize(deserializer)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn visit_unit<E>(self) -> Result<Self::Value, E> {
|
||||||
|
Ok(IgnoredAny)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn visit_seq<V>(self, mut visitor: V) -> Result<Self::Value, V::Error>
|
||||||
|
where
|
||||||
|
V: SeqVisitor<'de>,
|
||||||
|
{
|
||||||
|
while let Some(IgnoredAny) = try!(visitor.visit()) {
|
||||||
|
// Gobble
|
||||||
|
}
|
||||||
|
Ok(IgnoredAny)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn visit_map<V>(self, mut visitor: V) -> Result<Self::Value, V::Error>
|
||||||
|
where
|
||||||
|
V: MapVisitor<'de>,
|
||||||
|
{
|
||||||
|
while let Some((IgnoredAny, IgnoredAny)) = try!(visitor.visit()) {
|
||||||
|
// Gobble
|
||||||
|
}
|
||||||
|
Ok(IgnoredAny)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn visit_bytes<E>(self, bytes: &[u8]) -> Result<Self::Value, E>
|
||||||
|
where
|
||||||
|
E: Error,
|
||||||
|
{
|
||||||
|
let _ = bytes;
|
||||||
|
Ok(IgnoredAny)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for IgnoredAny {
|
impl<'de> Deserialize<'de> for IgnoredAny {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn deserialize<D>(deserializer: D) -> Result<IgnoredAny, D::Error>
|
fn deserialize<D>(deserializer: D) -> Result<IgnoredAny, D::Error>
|
||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
struct IgnoredAnyVisitor;
|
deserializer.deserialize_ignored_any(IgnoredAny)
|
||||||
|
|
||||||
impl<'de> Visitor<'de> for IgnoredAnyVisitor {
|
|
||||||
type Value = IgnoredAny;
|
|
||||||
|
|
||||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
formatter.write_str("anything at all")
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn visit_bool<E>(self, _: bool) -> Result<IgnoredAny, E> {
|
|
||||||
Ok(IgnoredAny)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn visit_i64<E>(self, _: i64) -> Result<IgnoredAny, E> {
|
|
||||||
Ok(IgnoredAny)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn visit_u64<E>(self, _: u64) -> Result<IgnoredAny, E> {
|
|
||||||
Ok(IgnoredAny)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn visit_f64<E>(self, _: f64) -> Result<IgnoredAny, E> {
|
|
||||||
Ok(IgnoredAny)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn visit_str<E>(self, _: &str) -> Result<IgnoredAny, E>
|
|
||||||
where
|
|
||||||
E: Error,
|
|
||||||
{
|
|
||||||
Ok(IgnoredAny)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn visit_none<E>(self) -> Result<IgnoredAny, E> {
|
|
||||||
Ok(IgnoredAny)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn visit_some<D>(self, deserializer: D) -> Result<IgnoredAny, D::Error>
|
|
||||||
where
|
|
||||||
D: Deserializer<'de>,
|
|
||||||
{
|
|
||||||
IgnoredAny::deserialize(deserializer)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn visit_newtype_struct<D>(self, deserializer: D) -> Result<IgnoredAny, D::Error>
|
|
||||||
where
|
|
||||||
D: Deserializer<'de>,
|
|
||||||
{
|
|
||||||
IgnoredAny::deserialize(deserializer)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn visit_unit<E>(self) -> Result<IgnoredAny, E> {
|
|
||||||
Ok(IgnoredAny)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn visit_seq<V>(self, mut visitor: V) -> Result<IgnoredAny, V::Error>
|
|
||||||
where
|
|
||||||
V: SeqVisitor<'de>,
|
|
||||||
{
|
|
||||||
while let Some(_) = try!(visitor.visit::<IgnoredAny>()) {
|
|
||||||
// Gobble
|
|
||||||
}
|
|
||||||
Ok(IgnoredAny)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn visit_map<V>(self, mut visitor: V) -> Result<IgnoredAny, V::Error>
|
|
||||||
where
|
|
||||||
V: MapVisitor<'de>,
|
|
||||||
{
|
|
||||||
while let Some((_, _)) = try!(visitor.visit::<IgnoredAny, IgnoredAny>()) {
|
|
||||||
// Gobble
|
|
||||||
}
|
|
||||||
Ok(IgnoredAny)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn visit_bytes<E>(self, _: &[u8]) -> Result<IgnoredAny, E>
|
|
||||||
where
|
|
||||||
E: Error,
|
|
||||||
{
|
|
||||||
Ok(IgnoredAny)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
deserializer.deserialize_ignored_any(IgnoredAnyVisitor)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user