When trying to use rustc-serialize to (d)e(n)code a struct containing two Strings in Rust 1.7, the compiler complains that there are too many impl candidates and doesn't know which one to choose.
The code:
#[derive(RustcDecodable, RustcEncodable, Debug)]
struct gonet {
ip: String,
mask: String,
}
The complaint:
src/bin/measurer.rs:18:5: 18:15 error: multiple applicable items in scope [E0034]
src/bin/measurer.rs:18 ip: String,
^~~~~~~~~~
src/bin/measurer.rs:16:26: 16:40 note: in this expansion of #[derive_RustcEncodable] (defined in src/bin/measurer.rs)
src/bin/measurer.rs:18:5: 18:15 help: run `rustc --explain E0034` to see a detailed explanation
src/bin/measurer.rs:18:5: 18:15 note: candidate #1 is defined in an impl of the trait `rustc_serialize::serialize::Encodable` for the type `str`
src/bin/measurer.rs:18 ip: String,
^~~~~~~~~~
src/bin/measurer.rs:16:26: 16:40 note: in this expansion of #[derive_RustcEncodable] (defined in src/bin/measurer.rs)
src/bin/measurer.rs:18:5: 18:15 note: candidate #2 is defined in an impl of the trait `rustc_serialize::serialize::Encodable` for the type `collections::string::String`
src/bin/measurer.rs:18 ip: String,
^~~~~~~~~~
src/bin/measurer.rs:16:26: 16:40 note: in this expansion of #[derive_RustcEncodable] (defined in src/bin/measurer.rs)
src/bin/measurer.rs:18:5: 18:15 note: candidate #3 is defined in an impl of the trait `rustc_serialize::serialize::Encodable` for the type `&_`
src/bin/measurer.rs:18 ip: String,
^~~~~~~~~~
src/bin/measurer.rs:16:26: 16:40 note: in this expansion of #[derive_RustcEncodable] (defined in src/bin/measurer.rs)
src/bin/measurer.rs:18:5: 18:15 note: candidate #4 is defined in an impl of the trait `radix_trie::keys::TrieKey` for the type `_`
src/bin/measurer.rs:18 ip: String,
^~~~~~~~~~
src/bin/measurer.rs:16:26: 16:40 note: in this expansion of #[derive_RustcEncodable] (defined in src/bin/measurer.rs)
src/bin/measurer.rs:19:5: 19:17 error: multiple applicable items in scope [E0034]
src/bin/measurer.rs:19 mask: String,
^~~~~~~~~~~~
src/bin/measurer.rs:16:26: 16:40 note: in this expansion of #[derive_RustcEncodable] (defined in src/bin/measurer.rs)
src/bin/measurer.rs:19:5: 19:17 help: run `rustc --explain E0034` to see a detailed explanation
src/bin/measurer.rs:19:5: 19:17 note: candidate #1 is defined in an impl of the trait `rustc_serialize::serialize::Encodable` for the type `str`
src/bin/measurer.rs:19 mask: String,
^~~~~~~~~~~~
src/bin/measurer.rs:16:26: 16:40 note: in this expansion of #[derive_RustcEncodable] (defined in src/bin/measurer.rs)
src/bin/measurer.rs:19:5: 19:17 note: candidate #2 is defined in an impl of the trait `rustc_serialize::serialize::Encodable` for the type `collections::string::String`
src/bin/measurer.rs:19 mask: String,
^~~~~~~~~~~~
src/bin/measurer.rs:16:26: 16:40 note: in this expansion of #[derive_RustcEncodable] (defined in src/bin/measurer.rs)
src/bin/measurer.rs:19:5: 19:17 note: candidate #3 is defined in an impl of the trait `rustc_serialize::serialize::Encodable` for the type `&_`
src/bin/measurer.rs:19 mask: String,
^~~~~~~~~~~~
src/bin/measurer.rs:16:26: 16:40 note: in this expansion of #[derive_RustcEncodable] (defined in src/bin/measurer.rs)
src/bin/measurer.rs:19:5: 19:17 note: candidate #4 is defined in an impl of the trait `radix_trie::keys::TrieKey` for the type `_`
src/bin/measurer.rs:19 mask: String,
^~~~~~~~~~~~
src/bin/measurer.rs:16:26: 16:40 note: in this expansion of #[derive_RustcEncodable] (defined in src/bin/measurer.rs)
My code also use the TrieKey trait from the radix_tree crate, which also has an encode() method.
I'd like to have both traits in scope as I use them both, but they conflict, so how can I specify which trait of String to use for deriving (if it is even possible)?
Not useing TrieKey works, but I'd like a solution that allows me to use both.
uses as possible, and check whether it compiles. It also may be some interference with dependency crates, although as far as I understand, Rust trait rules were designed exactly to avoid problems like this. - Vladimir Matveevderive(RustcEncodable). - oli_obk