Skip to content
This repository was archived by the owner on Sep 13, 2023. It is now read-only.

add full-throttle feature #70

Merged
merged 3 commits into from
May 28, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -13,14 +13,23 @@ keywords = ["cli", "prelude"]
[dependencies]
failure = "0.1.1"
failure_derive = "0.1.1"
serde = "1.0.27"
serde_derive = "1.0.27"
serde = { version="1.0.27", optional = true}
serde_derive = { version="1.0.27", optional = true }
structopt = "0.2"
structopt-derive = "0.2"
log = "0.4.1"
env_logger = "0.5.3"
glob = "0.2.11"
rayon = "1.0"
glob = { version = "0.2.11", optional = true }
rayon = { version = "1.0", optional = true }

[features]
default = ["full-throttle"]
full-throttle = [
"serde",
"serde_derive",
"glob",
"rayon",
]

[workspace]
members = [
22 changes: 14 additions & 8 deletions src/fs.rs
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
extern crate glob;

use std::path::{Path, PathBuf};
use std::io::{Read, Write, BufReader, BufWriter};
use std::io::{BufReader, BufWriter, Read, Write};
use std::fs::File;
use std::result::Result as StdResult;

@@ -31,10 +31,13 @@ pub use std::fs::create_dir_all as create_dir;
/// ```
pub fn read_file<P: AsRef<Path>>(path: P) -> Result<String> {
let path = path.as_ref();
ensure!(path.exists() && path.is_file(), "Path {:?} is not a file!", path);
ensure!(
path.exists() && path.is_file(),
"Path {:?} is not a file!",
path
);

let file = File::open(path)
.with_context(|_| format!("Could not open file {:?}", path))?;
let file = File::open(path).with_context(|_| format!("Could not open file {:?}", path))?;
let mut file = BufReader::new(file);

let mut result = String::new();
@@ -61,8 +64,8 @@ pub fn read_file<P: AsRef<Path>>(path: P) -> Result<String> {
pub fn write_to_file<P: AsRef<Path>>(path: P, content: &str) -> Result<()> {
let path = path.as_ref();

let file = File::create(path)
.with_context(|_| format!("Could not create/open file {:?}", path))?;
let file =
File::create(path).with_context(|_| format!("Could not create/open file {:?}", path))?;
let mut file = BufWriter::new(file);

file.write_all(content.as_bytes())
@@ -100,8 +103,11 @@ pub fn glob(pattern: &str) -> Result<Vec<PathBuf>> {
.filter_map(StdResult::ok)
.collect();

ensure!(files.get(0).is_some(), "No files match pattern `{}`", pattern);
ensure!(
files.get(0).is_some(),
"No files match pattern `{}`",
pattern
);

Ok(files)
}

53 changes: 37 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -6,37 +6,55 @@
#![allow(unused_imports)]
#![deny(missing_docs)]

#[macro_use] extern crate serde_derive;
#[cfg(feature = "full-throttle")]
#[macro_use]
extern crate serde_derive;
#[cfg(feature = "full-throttle")]
extern crate serde;

#[macro_use] extern crate structopt_derive;
#[macro_use]
extern crate structopt_derive;
extern crate structopt;

#[macro_use] extern crate failure_derive;
#[macro_use] extern crate failure;
#[macro_use]
extern crate failure_derive;
#[macro_use]
extern crate failure;

#[macro_use] extern crate log;
#[macro_use]
extern crate log;
extern crate env_logger;

#[cfg(feature = "full-throttle")]
extern crate rayon;

#[cfg(feature = "full-throttle")]
pub mod fs;
mod main_macro;

mod reexports {
#[doc(hidden)] pub use serde_derive::*;

#[doc(hidden)] pub use structopt_derive::*;
#[doc(hidden)] pub mod structopt {
pub use ::structopt::*;
#[cfg(feature = "full-throttle")]
#[doc(hidden)]
pub use serde_derive::*;

#[doc(hidden)]
pub use structopt_derive::*;
#[doc(hidden)]
pub mod structopt {
pub use structopt::*;
}
#[doc(hidden)] pub use structopt::StructOpt;
#[doc(hidden)]
pub use structopt::StructOpt;

#[doc(hidden)] pub use failure_derive::*;
#[doc(hidden)] pub use failure::*;
#[doc(hidden)]
pub use failure_derive::*;
#[doc(hidden)]
pub use failure::*;

#[doc(hidden)] pub use log::*;
#[doc(hidden)]
pub use log::*;

#[cfg(feature = "full-throttle")]
pub use rayon::prelude::*;
}

@@ -53,8 +71,11 @@ pub mod prelude {
/// A handy alias for `Result` that carries a generic error type.
pub type Result<T> = ::std::result::Result<T, ::failure::Error>;

#[cfg(feature = "full-throttle")]
pub use fs::*;

#[doc(hidden)] pub use env_logger::Builder as LoggerBuilder;
#[doc(hidden)] pub use log::Level as LogLevel;
#[doc(hidden)]
pub use env_logger::Builder as LoggerBuilder;
#[doc(hidden)]
pub use log::Level as LogLevel;
}