-
Notifications
You must be signed in to change notification settings - Fork 110
Derive RustcDecodable not working when rustc-serialize crate is imported inside a module #61
Comments
I think it is best practice to move all the extern crate statement in the lib.rs/main.rs file. That's what I always do. |
I should have checked the github issues first. Thanks for the feedback @gbersac. |
I am new to Rust and this issue bit me within minutes and I took me some time to find it here. So the question is, can this be fixed in the crate itself or is this a fundamental issue? The current usage statement didn't click for me:
So in the meantime it would be a good idea to update the usage section in README.md to mention main.rs and lib.rs explicitly. And to state if used anywhere else this issue applies. |
Is the crate root requirement a limitation of |
This is not a limitation of The code generated by RustcEncodable and RustcDecodable looks like this: impl ::rustc_serialize::Encodable for Test { /* ... */ }
impl ::rustc_serialize::Decodable for Test { /* ... */ } which requires rustc_serialize to be in the crate root. In Serde we avoid this problem by generating the following code instead: const IMPL_SERIALIZE_FOR_Test: () = {
extern crate serde as _serde;
impl _serde::Serialize for Test { /* ... */ }
};
const IMPL_DESERIALIZE_FOR_Test: () = {
extern crate serde as _serde;
impl _serde::Deserialize for Test { /* ... */ }
}; This works whether or not serde is in the crate root, in fact whether or not you even import serde anywhere yourself. |
I'm going to close this now that this crate is deprecated in favor of serde. We're discontinuing feature development in rustc-serialize but will still continue to merge bug fixes if they arise. |
When importing rustc-serialize inside a module,
[derive(RustcDecodable, RustcEncodable)]
fails.The code inside the module file:
When compiling I get the following errors:
The issue can be workaround by moving the imports to the
lib.rs
file.The text was updated successfully, but these errors were encountered: