'daki bir örneği türetirken birden fazla impl adayı rustc-serialize
- (d) e (n) kodu, Rust 1.7'de iki String
s içeren bir struct
kodunu kullanmaya çalışırken, derleyici çok fazla sayıda adayın olduğundan şikayetçi değildir ve hangisini seçeceğimi bilmek.Rust
kodu:
#[derive(RustcDecodable, RustcEncodable, Debug)]
struct gonet {
ip: String,
mask: String,
}
şikayet:
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 kodu da, aynı zamanda, bir encode()
yöntemi vardır radix_tree
sandık gelen TrieKey
özellik kullanın.
Her ikisini de kullandığım için her iki özelliğe de sahip olmak isterim, ancak çakışıyorlar, dolayısıyla türetmenin hangi özelliğinin String
türetme için kullanılacağını nasıl belirleyebilirim (eğer mümkünse)?
Değil use
TrieKey
eser ing ama use
hem beni tanıyan bir çözüm istiyorum.
Bu gerçekten * tuhaftır. [Bu] (https://gist.github.com/netvl/4c7afffc7ed8ec72717acd3e8617d1c0) programı sadece yapınızı içerir ve sadece iyi derler. Yapınızı farklı bir modülde çıkarmaya çalışın, mümkün olduğu kadar az "kullanımı" ile birleştirin ve derleyip derleme yapıp yapmadığını kontrol edin. Aynı zamanda, * bağımlılık kasaları ile bir etkileşim olabilir *, benim de anladığım kadarıyla, Rust özellik kuralları, bu gibi problemleri önlemek için tam olarak tasarlandı. –
[MCVE] (https://play.rust-lang.org/?gist=4855336da123370b3fdd9ef689917453&version=stable&backtrace=0) Bu, türetmenin (RustcEncodable) genişletilmesinde bir hijyen hatasıdır. –
Teşekkürler, bildirildi [burada] (https://github.com/rust-lang-nursery/rustc-serialize/issues/151). – NougatRillettes