extern crate serde;
use crate::serde::ser::Serialize;
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub enum HcNodeID {
None,
ID(usize)
}
impl serde::ser::Serialize for HcNodeID {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::ser::Serializer
{
match self {
HcNodeID::ID(id) => serializer.serialize_u64(*id as u64),
HcNodeID::None => serializer.serialize_str("INVALID"),
}
}
}
fn main() {
let mut the_builder = serde_hjson::builder::ObjectBuilder::new();;
let my_id : HcNodeID = HcNodeID::None;
let mut json_builder = the_builder.insert("id", my_id);
println!("{}", json_builder.unwrap());
}
And I get this error:
29 | let mut json_builder = the_builder.insert("id", my_id);
| ^^^^^^ the trait `serde::ser::Serialize` is not
implemented for `HcNodeID`
I'm sorry if this is an idiotic question, but I can't seem to understand what's going wrong. It seems like the trait implementation is right there, and other traits seem to work just fine.
Thanks for the info. I spent a few hours trying to bring serde-hjson up to date with the latest serde interfaces, but it started to feel like a can of worms. It's is a bit more of a project than I can bite off right now, but I may be able to set aside a few days for it in the future. hjson is just so much friendlier than normal json.
On a different note, it was not the best error from rustc, I must say. I had no idea that the compiler was trying to tell me that two incompatible versions of the trait existed simultaneously with the same name. That the version of the trait I was implementing isn't the version used by the crate I was calling.
Anyway, thanks for the info. Am I the only person who wants a working hjson crate, or is there value for the community if I invest the time to bring it up to date?