Struct serde::ser::impls::MapIteratorVisitor [] [src]

pub struct MapIteratorVisitor<Iter> {
    // some fields omitted
}

A serde::Visitor for (key, value) map iterators.

Examples

use std::collections::HashMap;
use serde::{Serialize, Serializer};
use serde::ser::impls::MapIteratorVisitor;

struct Map(HashMap<u32, u32>);

impl Serialize for Map {
    fn serialize<S>(&self, ser: &mut S) -> Result<(), S::Error>
        where S: Serializer,
    {
        ser.visit_map(MapIteratorVisitor::new(
            self.0.iter(),
            Some(self.0.len()),
        ))
    }
}

Methods

impl<K, V, Iter> MapIteratorVisitor<Iter> where Iter: Iterator<Item=(K, V)>

fn new(iter: Iter, len: Option<usize>) -> MapIteratorVisitor<Iter>

Construct a new MapIteratorVisitor<Iter>.

Trait Implementations

impl<K, V, I> MapVisitor for MapIteratorVisitor<I> where K: Serialize, V: Serialize, I: Iterator<Item=(K, V)>

fn visit<S>(&mut self, serializer: &mut S) -> Result<Option<()>, S::Error> where S: Serializer

fn len(&self) -> Option<usize>