Monday, 15 September 2014

How to decode JSON object with Rust keyword attribute name? -


I was wondering if it is possible to decode a JSON object in war, which has a feature name which is a correlation keyword is also. I am working with the rustc-serialize crate and my structure definition looks like this:

<[derive (rustcDecodable)] [MyObj {type: string}

compiler throws an error because type is a keyword is the exact compiler error message:

  Error: Expected identifier, keyword type type src / mysrc.rs: 23 type: string , ^ ~~~  
found

Sorry for the cheater question, I have just started trying for war.

You can use crate. It supports the renaming of the field

Your example may look like this:

# [derive (deserialize)] structure MyObj {# [serde (rename) = "Type")] type_name: string}

No comments:

Post a Comment