Timespec in a RustcEncodable/Decodable Struct


#1

I have a struct that I am applying the RustcEncodable and RustcDecodable attributes to. The struct contains a Timespec and the compiler is complaining that Timespec is missing the functions it needs to encode and decode itself. I find this odd as the code for Timespec has #[cfg_attr(feature = "rustc-serialize", derive(RustcEncodable, RustcDecodable))] and I do have rustc-serialize as a dependency in my Cargo.toml.

Is there something else that has to be done to have to compiler add the necessary functions to the Timespec structure?


#2

You need to activate the rustc-serialize feature in the crate where Timespec comes from. Features are only local to the crates, themselves.


#3

How do I activate it? Do I need to make a fork of the crate with a modified Cargo.toml?


#4

No, just change your dependency entry like this:

[dependencies.some_crate]
version = "..."
features = ["rustc-serialize"]

You can read more about it here.