use std::collections::BTreeMap;
use std::convert::{From, Into};
use std::borrow::ToOwned;
#[derive(Debug)]
enum Foo {
Bytes(Vec<u8>),
String(String),
I32(i32),
I64(i64),
Dict(Dict),
}
impl<'a> From<&'a [u8]> for Foo {
fn from(b: &'a [u8]) -> Self { Foo::Bytes(b.to_owned()) }
}
impl<'a> From<&'a str> for Foo {
fn from(s: &'a str) -> Self { Foo::String(s.to_owned()) }
}
impl From<i32> for Foo {
fn from(n: i32) -> Self { Foo::I32(n) }
}
impl From<i64> for Foo {
fn from(n: i64) -> Self { Foo::I64(n) }
}
impl From<Dict> for Foo {
fn from(d: Dict) -> Self { Foo::Dict(d) }
}
#[derive(Debug)]
pub struct Dict {
data: BTreeMap<Vec<u8>, Foo>
}
impl Dict {
pub fn push<K, V>(&mut self, key: K, val: V)
where K: Into<Vec<u8>>,
V: Into<Foo> {
self.data.insert(key.into(), val.into());
}
}
fn main() {}
dXNlIHN0ZDo6Y29sbGVjdGlvbnM6OkJUcmVlTWFwOwp1c2Ugc3RkOjpjb252ZXJ0Ojp7RnJvbSwgSW50b307CnVzZSBzdGQ6OmJvcnJvdzo6VG9Pd25lZDsKCiNbZGVyaXZlKERlYnVnKV0KZW51bSBGb28gewogICAgQnl0ZXMoVmVjPHU4PiksCiAgICBTdHJpbmcoU3RyaW5nKSwKICAgIEkzMihpMzIpLAogICAgSTY0KGk2NCksCiAgICBEaWN0KERpY3QpLAp9CgppbXBsPCdhPiBGcm9tPCYnYSBbdThdPiBmb3IgRm9vIHsKICAgIGZuIGZyb20oYjogJidhIFt1OF0pIC0+IFNlbGYgeyBGb286OkJ5dGVzKGIudG9fb3duZWQoKSkgfQp9CgppbXBsPCdhPiBGcm9tPCYnYSBzdHI+IGZvciBGb28gewogICAgZm4gZnJvbShzOiAmJ2Egc3RyKSAtPiBTZWxmIHsgRm9vOjpTdHJpbmcocy50b19vd25lZCgpKSB9Cn0KCmltcGwgRnJvbTxpMzI+IGZvciBGb28gewogICAgZm4gZnJvbShuOi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