extra: add ToJson for TreeMap.
This commit is contained in:
parent
9e67bc37ff
commit
bf1f69c156
1 changed files with 11 additions and 0 deletions
|
@ -27,6 +27,7 @@ use std::to_str;
|
|||
use serialize::Encodable;
|
||||
use serialize;
|
||||
use sort::Sort;
|
||||
use treemap::TreeMap;
|
||||
|
||||
/// Represents a json value
|
||||
pub enum Json {
|
||||
|
@ -1340,6 +1341,16 @@ impl<A:ToJson + Copy> ToJson for HashMap<~str, A> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<A:ToJson + Copy> ToJson for TreeMap<~str, A> {
|
||||
fn to_json(&self) -> Json {
|
||||
let mut d = HashMap::new();
|
||||
for self.iter().advance |(key, value)| {
|
||||
d.insert(copy *key, value.to_json());
|
||||
}
|
||||
Object(~d)
|
||||
}
|
||||
}
|
||||
|
||||
impl<A:ToJson> ToJson for Option<A> {
|
||||
fn to_json(&self) -> Json {
|
||||
match *self {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue