How do I fix Encodable/Decodable deprecation?

后端 未结 3 1477
灰色年华
灰色年华 2021-01-24 13:07

A few repos (e.g. https://github.com/sebcrozet/nalgebra) have errors along the lines of

warning: deriving(Decodable) is deprecated in favor of deriving(RustcDeco         


        
相关标签:
3条回答
  • 2021-01-24 13:17

    At least with 1.0.0-alpha the version 0.1.5 is always downloaded even if you specify the version in Cargo.toml. That version does not compile against the alpha:

       Compiling rustc-serialize v0.1.5
    /home/jsakkine/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.1.5/src/serialize.rs:175:42: 175:47 error: obsolete syntax: for Sized?
    /home/jsakkine/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.1.5/src/serialize.rs:175 pub trait Encodable, E> for Sized? {
                                                                                                                                                       ^~~~~
    note: no longer required. Traits (and their `Self` type) do not have the `Sized` bound by default
    /home/jsakkine/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.1.5/src/serialize.rs:381:35: 381:36 error: obsolete syntax: `Sized? T` syntax for removing the `Sized` bound
    /home/jsakkine/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.1.5/src/serialize.rs:381 impl, Sized? T: Encodable> Encodable for &'a T {
                                                                                                                                                ^
    note: write `T: ?Sized` instead
    /home/jsakkine/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.1.5/src/serialize.rs:387:31: 387:32 error: obsolete syntax: `Sized? T` syntax for removing the `Sized` bound
    /home/jsakkine/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.1.5/src/serialize.rs:387 impl, Sized? T: Encodable> Encodable for Box {
                                                                                                                                            ^
    /home/jsakkine/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.1.5/src/base64.rs:73:24: 73:29 error: obsolete syntax: for Sized?
    /home/jsakkine/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.1.5/src/base64.rs:73 pub trait ToBase64 for Sized? {
                                                                                                                                 ^~~~~
    note: no longer required. Traits (and their `Self` type) do not have the `Sized` bound by default
    /home/jsakkine/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.1.5/src/base64.rs:173:26: 173:31 error: obsolete syntax: for Sized?
    /home/jsakkine/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.1.5/src/base64.rs:173 pub trait FromBase64 for Sized? {
                                                                                                                                    ^~~~~
    /home/jsakkine/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.1.5/src/hex.rs:21:21: 21:26 error: obsolete syntax: for Sized?
    /home/jsakkine/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.1.5/src/hex.rs:21 pub trait ToHex for Sized? {
                                                                                                                           ^~~~~
    note: no longer required. Traits (and their `Self` type) do not have the `Sized` bound by default
    /home/jsakkine/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.1.5/src/hex.rs:57:23: 57:28 error: obsolete syntax: for Sized?
    /home/jsakkine/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.1.5/src/hex.rs:57 pub trait FromHex for Sized? {
                                                                                                                             ^~~~~
    /home/jsakkine/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.1.5/src/json.rs:396:30: 396:33 error: expected identifier, found keyword `mut`
    /home/jsakkine/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.1.5/src/json.rs:396     escape_bytes(writer, buf[mut ..len])
                                                                                                                                      ^~~
    /home/jsakkine/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.1.5/src/json.rs:401:20: 401:21 error: expected one of `(`, `+`, `::`, `;`, or `]`, found `,`
    /home/jsakkine/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.1.5/src/json.rs:401     static BUF: [u8, ..LEN] = [b' ', ..LEN];
                                                                                                                            ^
    Could not compile `rustc-serialize`.
    
    To learn more, run the command again with --verbose.
    
    0 讨论(0)
  • 2021-01-24 13:24

    I got this working by using 0.2 version of rustc-serialize:

    [dependencies]
    rustc-serialize = "0.2"
    
    0 讨论(0)
  • 2021-01-24 13:34

    I believe that your error comes from this commit:

    This commit completes the deprecation story for the in-tree serialization library. The compiler will now emit a warning whenever it encounters deriving(Encodable) or deriving(Decodable), and the library itself is now marked #[unstable] for when feature staging is enabled.

    All users of serialization can migrate to the rustc-serialize crate on crates.io which provides the exact same interface as the libserialize library in-tree. The new deriving modes are named RustcEncodable and RustcDecodable and require extern crate "rustc-serialize" as rustc_serialize at the crate root in order to expand correctly.

    To migrate all crates, add the following to your Cargo.toml:

    [dependencies]
    rustc-serialize = "0.1.1"
    

    And then add the following to your crate root:

    extern crate "rustc-serialize" as rustc_serialize;
    

    Finally, rename Encodable and Decodable deriving modes to RustcEncodable and RustcDecodable.

    0 讨论(0)
提交回复
热议问题