Created
April 17, 2015 06:07
-
-
Save nicolai86/33472bfc7b546521c9a6 to your computer and use it in GitHub Desktop.
whitespace panic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "test" | |
version = "0.1.0" | |
authors = ["Raphael Randschau <[email protected]>"] | |
[dependencies] | |
serde_macros = "0.3.1" | |
[dependencies.serde] | |
git = "https://github.com/oli-obk/rust-serde.git" | |
rev = 'xml' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(custom_derive, plugin, custom_attribute)] | |
#![plugin(serde_macros)] | |
extern crate serde; | |
use serde::xml::{ | |
from_str, | |
}; | |
#[derive(Serialize, Deserialize)] | |
#[allow(non_snake_case)] | |
struct TheSender { | |
name: String, | |
} | |
#[derive(Serialize, Deserialize)] | |
#[allow(non_snake_case)] | |
struct CurrencyCube { | |
currency: String, | |
rate: String, | |
} | |
#[derive(Serialize, Deserialize)] | |
#[allow(non_snake_case)] | |
struct InnerCube { | |
Cube: Vec<CurrencyCube>, | |
} | |
#[derive(Serialize, Deserialize)] | |
#[allow(non_snake_case)] | |
struct OuterCube { | |
Cube: Vec<InnerCube>, | |
} | |
#[derive(Serialize, Deserialize)] | |
#[allow(non_snake_case)] | |
struct Envelope { | |
subject: String, | |
Sender: TheSender, | |
Cube: OuterCube, | |
} | |
fn main() { | |
let s = r#" | |
<?xml version="1.0" encoding="UTF-8"?> | |
<gesmes:Envelope xmlns:gesmes="http://www.gesmes.org/xml/2002-08-01" xmlns="http://www.ecb.int/vocabulary/2002-08-01/eurofxref"> | |
<gesmes:subject>Reference rates</gesmes:subject> | |
<gesmes:Sender> | |
<gesmes:name>European Central Bank</gesmes:name> | |
</gesmes:Sender> | |
<Cube></Cube> | |
</gesmes:Envelope>"#; | |
let a: Envelope = from_str(s).unwrap(); | |
println!("Hello, world!\n{}", a.subject); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(custom_derive, plugin, custom_attribute)] | |
#![plugin(serde_macros)] | |
extern crate serde; | |
use serde::xml::{ | |
from_str, | |
}; | |
#[derive(Serialize, Deserialize)] | |
#[allow(non_snake_case)] | |
struct TheSender { | |
name: String, | |
} | |
#[derive(Serialize, Deserialize)] | |
#[allow(non_snake_case)] | |
struct CurrencyCube { | |
currency: String, | |
rate: String, | |
} | |
#[derive(Serialize, Deserialize)] | |
#[allow(non_snake_case)] | |
struct InnerCube { | |
Cube: Vec<CurrencyCube>, | |
} | |
#[derive(Serialize, Deserialize)] | |
#[allow(non_snake_case)] | |
struct OuterCube { | |
Cube: Vec<InnerCube>, | |
} | |
#[derive(Serialize, Deserialize)] | |
#[allow(non_snake_case)] | |
struct Envelope { | |
subject: String, | |
Sender: TheSender, | |
Cube: OuterCube, | |
} | |
fn main() { | |
let s = r#" | |
<?xml version="1.0" encoding="UTF-8"?> | |
<gesmes:Envelope xmlns:gesmes="http://www.gesmes.org/xml/2002-08-01" xmlns="http://www.ecb.int/vocabulary/2002-08-01/eurofxref"> | |
<gesmes:subject>Reference rates</gesmes:subject> | |
<gesmes:Sender> | |
<gesmes:name>European Central Bank</gesmes:name> | |
</gesmes:Sender> | |
<Cube> </Cube> | |
</gesmes:Envelope>"#; | |
let a: Envelope = from_str(s).unwrap(); | |
println!("Hello, world!\n{}", a.subject); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment