2016-04-12 1 views
0

При попытке использовать rustc-serialize в (d) код a struct, содержащий два String s в Rust 1.7, компилятор жалуется, что существует слишком много кандидатов-кандидатов и не знаете, какой из них выбрать.Множественный кандидат-кандидат при получении экземпляра в Rust

Код:

#[derive(RustcDecodable, RustcEncodable, Debug)] 
struct gonet { 
    ip: String, 
    mask: String, 
} 

Жалоба:

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) 

Мой код также использовать TrieKey черты от radix_tree клети, которая также имеет encode() метод.

Я хотел бы иметь обе характеристики в области видимости, поскольку я использую их оба, но они конфликтуют, так как я могу указать, какую черту String использовать для получения (если это возможно)?

Не useTrieKey работает, но я хотел бы получить решение, которое позволяет мне use.

+1

Это действительно странно. [This] (https://gist.github.com/netvl/4c7afffc7ed8ec72717acd3e8617d1c0) программа содержит только вашу структуру, и она компилируется просто отлично. Попытайтесь извлечь вашу структуру в отдельный модуль, используя как можно меньше 'use' и проверьте, компилируется ли она. Это также может * быть некоторым вмешательством в ящики с зависимостями, хотя, насколько я понимаю, правила поведения Rust были разработаны точно, чтобы избежать подобных проблем. –

+2

[MCVE] (https://play.rust-lang.org/?gist=4855336da123370b3fdd9ef689917453&version=stable&backtrace=0) Это ошибка гигиены в расширении 'getive (RustcEncodable)'. –

+0

Спасибо, сообщили [здесь] (https://github.com/rust-lang-nursery/rustc-serialize/issues/151). – NougatRillettes

ответ

0

Как сказано в комментариях к оригинальному сообщению, это на самом деле bug. Исправление составляет available.

Смежные вопросы