Compler error re: serialize


#1

Hello All,

I’m trying to compile and run the program found here:

Line 6 is: extern crate “rustc-serialize” as rustc_serialize;

Error when trying to compile is:
error: expected identifier, found "rustc-serialize"
–> main.rs:6:14
|
6 | extern crate “rustc-serialize” as rustc_serialize;
| ^^^^^^^^^^^^^^^^^

error: aborting due to previous error

My searches online show that there have been issues with serialize, but I haven’t found how to make this work.

Suggestions/solutions are much appreciated.

John

NB running Rust version: rustc 1.20.0 (f3d6973f4 2017-08-27) on Ubuntu 16.0.4


#2

The extern crate argument is an identifier, not a string, in this case it should be extern crate rustc-serialize (as is not needed here). However - why you would to use deprecated crate, when the supported replacement is visible in README which is rendered both on github and crates.io?


#3

That code is 3 years old, from before the Rust 1.0 release.


#4

Thanks for getting back to me.
When I change the line from extern crate “rustc-serialize” as rustc_serialize; to extern crate rustc-serialize;
I get another error:

error : expected one of ; or as, found -
–> main.rs:6:19

6 | extern crate rustc-serialize;

^ expected one of ; or as here

error : aborting due to previous error

When I try extern crate rustc_serialize;
I get another error:

error[E0463] : can’t find crate for docopt_macros
–> main.rs:2:11

2 | #![plugin(docopt_macros)]

^^^^^^^^^^^^^ can’t find crate

error : aborting due to previous error

Please note that I just picked up Rust yesterday and don’t yet know how to use the available resources to solve this problem.

Thanks again,

John


#5

You should look into serde for serialization needs and into clap for cmdline arg parsing. Both are crates available on crates.io.


#6

Thanks very much for your feedback.

Looks like both e xtern crate rustc-serialize and e xtern crate serde
prevent compiler error.

Haven’t solved the error[E0463] : can’t find crate for docopt_macros yet.

And yes the code is a few years old–a long time for rapidly evolving language.
Would it be possible to install a version of rust from 2015 that would compile and run without errors?
This approach would have the advantage of getting the program working.

Thanks again,

John


#7

So you should switch to serde here and forget rustc-serialize.

And use clap instead of docopt for cmdline arg parsing.

I would strongly recommend that you get the code working on current Rust. There’s little point making it work on a 2+ yrs old version and you’re unlikely to receive help from the community on such an old version.