1
use serde::ser::{Serialize, Serializer};
2

            
3
use crate::value::Value;
4

            
5
impl Serialize for Value {
6
120
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
7
120
    where
8
120
        S: Serializer,
9
120
    {
10
8
        match *self {
11
8
            Value::Bool(b) => serializer.serialize_bool(b),
12
16
            Value::Char(c) => serializer.serialize_char(c),
13
8
            Value::Map(ref m) => Serialize::serialize(m, serializer),
14
56
            Value::Number(ref number) => Serialize::serialize(number, serializer),
15
4
            Value::Option(Some(ref o)) => serializer.serialize_some(o.as_ref()),
16
4
            Value::Option(None) => serializer.serialize_none(),
17
8
            Value::String(ref s) => serializer.serialize_str(s),
18
4
            Value::Bytes(ref b) => serializer.serialize_bytes(b),
19
8
            Value::Seq(ref s) => Serialize::serialize(s, serializer),
20
4
            Value::Unit => serializer.serialize_unit(),
21
        }
22
120
    }
23
}