rusoto_codegen/
lib.rs

1#![cfg_attr(feature = "nightly-testing", feature(plugin))]
2#![cfg_attr(feature = "nightly-testing", plugin(clippy))]
3
4extern crate inflector;
5#[macro_use]
6extern crate lazy_static;
7extern crate regex;
8extern crate serde;
9extern crate serde_json;
10extern crate hyper;
11
12#[macro_use]
13extern crate serde_derive;
14
15use std::fs::File;
16use std::io::BufReader;
17use std::path::Path;
18
19use botocore::Service as BotocoreService;
20use generator::generate_source;
21
22pub mod botocore;
23pub mod generator;
24mod serialization;
25mod util;
26
27const BOTOCORE_DIR: &'static str = concat!(env!("CARGO_MANIFEST_DIR"), "/botocore/botocore/data/");
28
29pub struct Service {
30    pub name: String,
31    protocol_date: String,
32}
33
34impl Service {
35    pub fn new<S>(name: S, protocol_date: S) -> Self
36        where S: Into<String> {
37        Service {
38            name: name.into(),
39            protocol_date: protocol_date.into(),
40        }
41    }
42}
43
44pub fn generate(service: Service, output_path: &Path) -> i32 {
45    let destination_path = output_path.join(format!("{}.rs", service.name));
46    let botocore_service_data_path = Path::new(BOTOCORE_DIR)
47        .join(format!("{}/{}/service-2.json", service.name, service.protocol_date));
48
49    botocore_generate(botocore_service_data_path.as_path(),
50                                        destination_path.as_path());
51
52    return 1;
53}
54
55fn botocore_generate(input_path: &Path, output_path: &Path) {
56    let input_file = File::open(input_path).expect(&format!(
57        "{:?} not found",
58        input_path,
59    ));
60
61    let service_data_as_reader = BufReader::new(input_file);
62
63    let service: BotocoreService = serde_json::from_reader(service_data_as_reader).expect(&format!(
64        "Could not convert JSON in {:?} to Service",
65        input_path,
66    ));
67
68    match generate_source(&service, output_path) {
69        Ok(()) => {},
70        _ => panic!("Failed to write file at {:?}", output_path)
71    }
72}