N00b question: debugging Serialize trait implementation

Here's my code:

extern crate serde;
use crate::serde::ser::Serialize;

#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub enum HcNodeID {

impl serde::ser::Serialize for HcNodeID {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
        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.

Thank you!

What versions of serde and serde_hjson are you using?

Thanks for the reply!

In my Cargo.toml file, I have:

serde = "0.9"
serde-hjson = "*"

I started with:

serde = "*"
serde-hjson = "*"

But then I read somewhere that a version incompatibility might be the problem, so I tried a bunch of permutations, but ultimately nothing changed.

serde = "1.0"

and above doesn't compile, giving the error:

error[E0412]: cannot find type `NonZeroI8` in module `num`

And a whole bunch more like it.

The serde-hjson crate is abandoned and does not support any serde version from the past 3 years. I would recommend not using it.

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?

Thanks again.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.