You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.
use rustc_serialize::json::{Json,Decoder};use rustc_serialize::Decodable;#[derive(RustcDecodable)]pubstructArtist{name:String,images:Vec<Image>}implDecodableforArtist{fndecode<D: rustc_serialize::Decoder>(decoder:&mutD) -> Result<Artist,D::Error>{// stuff}}
src/main.rs:15:10: 15:24 error: conflicting implementations for trait rustc_serialize::serialize::Decodable` [E0119]
src/main.rs:15 #[derive(RustcDecodable)]
^~~~~~~~~~~~~~
src/main.rs:15:10: 15:24 note: in expansion of #[derive_RustcDecodable]
src/main.rs:15:10: 15:24 note: expansion site
src/main.rs:20:1: 24:2 note: note conflicting implementation here
src/main.rs:20 impl Decodable for Artist {
src/main.rs:21 fn decode<D: rustc_serialize::Decoder>(decoder: &mut D) -> Result<Artist, D::Error> {
src/main.rs:22 // stuff
src/main.rs:23 }
src/main.rs:24 }
error: aborting due to previous error
Also, if I write rustc_serialize::Decoder (line 11) simply as Decoder, than I need to import rustc_serialize::Decoder and remove use rustc_serialize::json::Decoder;, but than I can't Decoder::new() anymore.
The text was updated successfully, but these errors were encountered:
Well, if you have derive(RustcDecodable), then that is going to implement Decodable for you automatically. If you also provide your own impl for Decodable, then you'll have two impls for the same type on the same trait. That will cause the "conflicting impls" error you're seeing.
The conflict with Decoder is due to the fact that rustc_serialize::Decoder is a trait and rustc_serialize::json::Decoder is a type specifically for decoding JSON.
Ok, now that is clear to me.
About the second question, I was wondering a way to avoid expliciting the rustc_serialize for using the right Decoder, but it's not a great deal after all.
@RoxasShadow You could do use rustc_serialize::Decoder as RustcDecoder and then use RustcDecoder instead of Decoder for your trait bound. Alternatively, use rustc_serialize::json::Decoder as JsonDecoder.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Can anyone enlighten me about this?
Also, if I write
rustc_serialize::Decoder
(line 11) simply asDecoder
, than I need to importrustc_serialize::Decoder
and removeuse rustc_serialize::json::Decoder;
, but than I can'tDecoder::new()
anymore.The text was updated successfully, but these errors were encountered: