如何修复Encodable / Decodable弃用?

时间:2014-12-25 20:49:55

标签: rust

一些回购(例如https://github.com/sebcrozet/nalgebra)在

方面存在错误
warning: deriving(Decodable) is deprecated in favor of deriving(RustcDecodable).

Decodable原因取代RustcDecodable

error: attempt to bound type parameter with a nonexistent trait `rustc_serialize::Decoder`

如何更新这些内容?

3 个答案:

答案 0 :(得分:5)

我认为您的错误来自this commit

  

此提交完成了树内的弃用故事   序列化库。编译器现在会发出警告   遇到deriving(Encodable)deriving(Decodable),以及。{   库功能本身现在标记为#[unstable],用于功能分段   启用。

     

所有序列化用户都可以迁移到rustc-serialize包   在crates.io上,它提供了完全相同的界面   libserialize库in-tree。新的派生模式被命名   {c}根RustcEncodableRustcDecodable并要求extern crate "rustc-serialize" as rustc_serialize   正确扩展。

     

要迁移所有包,请将以下内容添加到Cargo.toml

[dependencies]
rustc-serialize = "0.1.1"
     

然后将以下内容添加到您的包根:

extern crate "rustc-serialize" as rustc_serialize;
     

最后,将EncodableDecodable导出模式重命名为   RustcEncodableRustcDecodable

答案 1 :(得分:1)

至少在1.0.0-alpha下,即使您在Cargo.toml中指定版本,也始终会下载0.1.5版本。该版本不会针对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.

答案 2 :(得分:1)

我使用0.2版本的rustc-serialize来实现这个目的:

[dependencies]
rustc-serialize = "0.2"