Skip to content

Commit

Permalink
Add support for Rust Stable (v1.8) via serde codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnau Siches committed Apr 24, 2016
1 parent 29d3370 commit 367c26a
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 105 deletions.
99 changes: 61 additions & 38 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@
name = "tflgtfs"
version = "0.1.0"
authors = ["Tom Burdick <[email protected]>"]
build = "build.rs"

[features]
default = ["serde_codegen"]
nightly = ["serde_macros"]

[build-dependencies]
serde_codegen = { version = "0.7", optional = true }
syntex = "*"

[dependencies]
ansi_term = "0.7"
clap = "2.2"
clippy = "*"
csv = "0.14"
env_logger = "0.3"
hyper = "0.8"
Expand All @@ -16,4 +24,4 @@ rust-crypto = "0.2"
scoped_threadpool = "0.1"
serde = "0.7"
serde_json = "0.7"
serde_macros = "0.7"
serde_macros = { version = "0.7", optional = true }
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ OPENSSL_INCLUDE_DIR=/usr/local/opt/openssl/include cargo build --release

You will find the binary in `./target/release/`.


## Usage

Check the help `./target/release/tflgtfs help` for details.
Expand All @@ -38,6 +39,12 @@ You can do it in one shot via:
You will find the resulting GTFS files inside `./gtfs`.


## Development

If you intend to improve this tool please install [Cargo Clippy][cargo-clippy]
to make sure your changes are aligned with our code conventions.


## License

See [License](./LICENSE).
Expand All @@ -46,3 +53,4 @@ See [License](./LICENSE).
[tfl-cli]: https://github.com/CommuteStream/tflgtfs/
[tfl-api]: https://api.tfl.gov.uk/
[gtfs]: https://developers.google.com/transit/gtfs/
[cargo-clippy]: https://crates.io/crates/cargo-clippy
29 changes: 29 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#[cfg(not(feature = "serde_macros"))]
mod inner {
extern crate syntex;
extern crate serde_codegen;

use std::env;
use std::path::Path;

pub fn main() {
let out_dir = env::var_os("OUT_DIR").unwrap();

let src = Path::new("src/main.rs.in");
let dst = Path::new(&out_dir).join("main.rs");

let mut registry = syntex::Registry::new();

serde_codegen::register(&mut registry);
registry.expand("", &src, &dst).unwrap();
}
}

#[cfg(feature = "serde_macros")]
mod inner {
pub fn main() {}
}

fn main() {
inner::main();
}
73 changes: 8 additions & 65 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#![feature(custom_derive, plugin)]
#![plugin(serde_macros)]
#![plugin(clippy)]
#![cfg_attr(feature = "serde_macros", feature(custom_derive, plugin))]
#![cfg_attr(feature = "serde_macros", plugin(serde_macros))]

#![cfg_attr(feature="clippy", feature(plugin))]
#![cfg_attr(feature="clippy", plugin(clippy))]

#[macro_use] extern crate clap;
#[macro_use] extern crate log;
Expand All @@ -15,66 +16,8 @@ extern crate scoped_threadpool;
extern crate serde;
extern crate serde_json;

mod cmd;
mod format;
mod geometry;
mod gtfs;
mod tfl;
#[cfg(feature = "serde_macros")]
include!("main.rs.in");

use clap::{Arg, App, SubCommand};
use format::{OutputFormat};

fn arg_format<'a, 'b>() -> Arg<'a, 'b> {
Arg::with_name("format")
.help("Output format")
.possible_values(&["gtfs"])
.long("format")
.value_name("format")
}

fn main() {
env_logger::init().unwrap();

let matches = App::new("tfl")
.version(env!("CARGO_PKG_VERSION"))
.about("Tfl consumer")
.subcommand(SubCommand::with_name("fetch-lines")
.about("Fetch lines from Tfl")
.arg(arg_format())
.arg(Arg::with_name("threads")
.help("Number of threads. Defaults to 5")
.long("threads")
.value_name("number"))
.arg(Arg::with_name("sample")
.help("Take a sample of the given size")
.long("sample")
.value_name("size")))
.subcommand(SubCommand::with_name("transform")
.about("Transform cached data to the given format")
.arg(arg_format()
.index(1)
.required(true))
.arg(Arg::with_name("threads")
.help("Number of threads. Defaults to 5")
.long("threads")
.value_name("number"))
.arg(Arg::with_name("sample")
.help("Take a sample of the given size")
.long("sample")
.value_name("size")))
.get_matches();

if let Some(ref matches) = matches.subcommand_matches("fetch-lines") {
let format = value_t!(matches, "format", OutputFormat).unwrap_or(OutputFormat::None);
let thread_number = value_t!(matches, "threads", u32).unwrap_or(5);
let sample_size = value_t!(matches, "sample", usize).ok();
cmd::fetch_lines(format, thread_number, sample_size);
}

if let Some(ref matches) = matches.subcommand_matches("transform") {
let format = value_t!(matches, "format", OutputFormat).unwrap_or_else(|e| e.exit());
let thread_number = value_t!(matches, "threads", u32).unwrap_or(5);
let sample_size = value_t!(matches, "sample", usize).ok();
cmd::transform(format, thread_number, sample_size);
}
}
#[cfg(not(feature = "serde_macros"))]
include!(concat!(env!("OUT_DIR"), "/main.rs"));
Loading

0 comments on commit 367c26a

Please sign in to comment.