What's up with rustc-serialize?

I have two questions about rustc-serialize.

  1. What is the future of rustc-serialize? I read this StackOverflow discussion but I'm unclear on the implications. Is it intended that these serialization modules will eventually be updated and reincorporated as std::serialize, or are JSON/hex/b64 serialization intended to be in the domain of crates.io from now on?

  2. The base64 module is not well-documented & I'm unclear on its use. I have owned Strings which I want to decode to integers. The base64 module implements methods for converting base 64 &strs and &[u8]s to byte sequences; is the limitation of this just because the implementation isn't finished or am I just missing something about how base64 is intended to be used?

1 Like

Not a Rust team member, just a random lurker. Everything I say is based on second hand evidence.

For 1. - In glorious future serialize will be replaced with rust-serde(2). The current interfaces are stubs, because Rust tries to be backwards compatible. For serialization to land, this will require compiler plugins which can't land on time.

Can't answer question 1, as that's more of a hypothetical and I'm not on the core team.

For question 2, you can execute any method that operates on &str on an owned String. This is because String implements Deref for str (see the RFC in which this was introduced), and deref coercion means that this will happen automatically without having to write the &* that it initially required.

So this actually works:

extern crate "rustc-serialize" as rustc_serialize;
use rustc_serialize::base64::FromBase64;

fn main() {
    let s: String = "SGVsbG8sIFdvcmxkIQ==".to_string();
    let v = s.from_base64().unwrap();
    println!("{}", String::from_utf8(v).unwrap());
}

Oh, great! Thanks, I was completely unaware of that.