json_map_serializer 0.1.3

Crate for easy serializing json maps from sequense of pairs
Documentation
use super::Pair;
use crate::{Error, Result};

pub struct PairBuilder<K, V> {
    pub key: Option<K>,
    pub value: Option<V>
}

impl<K, V> Default for PairBuilder<K, V> {
    fn default() -> Self {
        PairBuilder {
            key: None,
            value: None
        }
    }
}

impl<K, V> PairBuilder<K, V> {
    pub fn new() -> PairBuilder<K, V> {
        PairBuilder::default()
    }

    pub fn build(self) -> Result<Pair<K,V>>{
        Ok(Pair {
            key: self.key.ok_or(Error::NotAPair)?,
            value: self.value.ok_or(Error::NotAPair)?
        })
    }
}