Created
March 7, 2017 17:06
-
-
Save anonymous/5760e9bb9d8ccc69f901d58c491342dd to your computer and use it in GitHub Desktop.
Rust code shared from the playground
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
extern crate serde; | |
#[macro_use] | |
extern crate serde_json; | |
#[macro_use] | |
extern crate serde_derive; | |
use serde_json::Value; | |
#[derive(Serialize, Deserialize)] | |
struct SearchResponse { | |
resultCount: u32, | |
results: Vec<Result> | |
} | |
#[derive(Serialize, Deserialize)] | |
struct Result { | |
#[serde(skip_serializing_if="Option::is_none")] | |
legislation: Option<LegislationResult>, | |
#[serde(skip_serializing_if="Option::is_none")] | |
case: Option<CaseResult> | |
} | |
#[derive(Serialize, Deserialize)] | |
struct LegislationResult { | |
databaseId: String, | |
legislationId: String, | |
title: String, | |
citation: String, | |
#[serde(rename = "type")] | |
legislationType: String | |
} | |
#[derive(Serialize, Deserialize)] | |
struct CaseResult { | |
databaseId: String, | |
caseId: String, | |
title: String, | |
citation: String | |
} | |
fn main() { | |
let data = r#" | |
{ | |
"resultCount": 1681318, | |
"results": [{ | |
"case": { | |
"databaseId": "qccs", | |
"caseId": { | |
"fr": "2014qccs985" | |
}, | |
"title": "Dupuis c. Québec (Procureur général)", | |
"citation": "2014 QCCS 985 (CanLII)" | |
} | |
}, { | |
"case": { | |
"databaseId": "qccs", | |
"caseId": { | |
"fr": "2004canlii49463" | |
}, | |
"title": "C. O. c. Ch. L.", | |
"citation": "2004 CanLII 49463 (QC CS)" | |
} | |
}, { | |
"case": { | |
"databaseId": "qcclp", | |
"caseId": { | |
"fr": "2013qcclp5554" | |
}, | |
"title": "Laliberté et Micmacs of Gesgapegiag", | |
"citation": "2013 QCCLP 5554 (CanLII)" | |
} | |
}, { | |
"case": { | |
"databaseId": "qccsj", | |
"caseId": { | |
"fr": "2011qccsj613" | |
}, | |
"title": "Anonyme — 11613", | |
"citation": "2011 QCCSJ 613 (CanLII)" | |
} | |
}, { | |
"case": { | |
"databaseId": "qctaq", | |
"caseId": { | |
"fr": "2006canlii73436" | |
}, | |
"title": "M.R. c. Québec (Procureur général)", | |
"citation": "2006 CanLII 73436 (QC TAQ)" | |
} | |
}, { | |
"case": { | |
"databaseId": "qccrt", | |
"caseId": { | |
"fr": "2006qccrt333" | |
}, | |
"title": "Martel c. Bois d\u0027Énergie inc.", | |
"citation": "2006 QCCRT 333 (CanLII)" | |
} | |
}, { | |
"case": { | |
"databaseId": "qcdag", | |
"caseId": { | |
"fr": "2015canlii77281" | |
}, | |
"title": "Syndicat des cols bleus regroupés de Montréal, section locale 301 c Montréal (ville)", | |
"citation": "2015 CanLII 77281 (QC SAT)" | |
} | |
}, { | |
"case": { | |
"databaseId": "qccs", | |
"caseId": { | |
"fr": "2014qccs2218" | |
}, | |
"title": "Grenier c. Régie des marchés agricoles et alimentaires du Québec", | |
"citation": "2014 QCCS 2218 (CanLII)" | |
} | |
}, { | |
"case": { | |
"databaseId": "qccq", | |
"caseId": { | |
"fr": "2006qccq4301" | |
}, | |
"title": "Mathieu, Carrier, s.e.n.c. c. Tardif", | |
"citation": "2006 QCCQ 4301 (CanLII)" | |
} | |
}, { | |
"case": { | |
"databaseId": "qccsj", | |
"caseId": { | |
"fr": "2016qccsj975" | |
}, | |
"title": "Anonyme — 16978", | |
"citation": "2016 QCCSJ 975 (CanLII)" | |
} | |
}] | |
} | |
"#; | |
let sr: SearchResponse = serde_json::from_str(data).unwrap(); | |
println!("Hello, world! {}", sr.resultCount); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment