Split crate into a binary and a library
Split imdl into a binary, `src/main.rs`, and a library, `src/lib.rs`. This will enable benchmarking, fuzz testing, and anything that requires making `imdl` functions accessible another crate. type: reform
This commit is contained in:
parent
c1c8d3cb89
commit
1b2d79b4a5
|
@ -15,7 +15,7 @@ pub(crate) use std::{
|
||||||
num::{ParseFloatError, ParseIntError, TryFromIntError},
|
num::{ParseFloatError, ParseIntError, TryFromIntError},
|
||||||
ops::{AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign},
|
ops::{AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign},
|
||||||
path::{self, Path, PathBuf},
|
path::{self, Path, PathBuf},
|
||||||
process::{self, ExitStatus},
|
process::ExitStatus,
|
||||||
str::{self, FromStr},
|
str::{self, FromStr},
|
||||||
string::FromUtf8Error,
|
string::FromUtf8Error,
|
||||||
sync::Once,
|
sync::Once,
|
||||||
|
|
|
@ -34,7 +34,7 @@ pub(crate) const PROGRESS_CHARS: &str = "█▉▊▋▌▍▎▏ ";
|
||||||
/// Digits are ordered from least significant to most significant from
|
/// Digits are ordered from least significant to most significant from
|
||||||
/// top to bottom, and then left to right, like so:
|
/// top to bottom, and then left to right, like so:
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```text
|
||||||
/// ╔═════╗
|
/// ╔═════╗
|
||||||
/// ║ 0 4 ║
|
/// ║ 0 4 ║
|
||||||
/// ║ 1 5 ║
|
/// ║ 1 5 ║
|
||||||
|
|
|
@ -77,7 +77,7 @@ impl Env {
|
||||||
/// To enable logging in those tests, call `Env::initialize_logging()` like
|
/// To enable logging in those tests, call `Env::initialize_logging()` like
|
||||||
/// so:
|
/// so:
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```no_run
|
||||||
/// #[test]
|
/// #[test]
|
||||||
/// fn foo() {
|
/// fn foo() {
|
||||||
/// Env::initialize_logging();
|
/// Env::initialize_logging();
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::*;
|
use crate::common::*;
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
|
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
|
||||||
pub(crate) struct Infohash {
|
pub(crate) struct Infohash {
|
||||||
|
|
106
src/lib.rs
Normal file
106
src/lib.rs
Normal file
|
@ -0,0 +1,106 @@
|
||||||
|
#![deny(clippy::all, clippy::pedantic, clippy::restriction)]
|
||||||
|
#![allow(
|
||||||
|
clippy::else_if_without_else,
|
||||||
|
clippy::enum_glob_use,
|
||||||
|
clippy::float_arithmetic,
|
||||||
|
clippy::float_cmp,
|
||||||
|
clippy::implicit_return,
|
||||||
|
clippy::indexing_slicing,
|
||||||
|
clippy::integer_arithmetic,
|
||||||
|
clippy::integer_division,
|
||||||
|
clippy::large_enum_variant,
|
||||||
|
clippy::missing_docs_in_private_items,
|
||||||
|
clippy::missing_inline_in_public_items,
|
||||||
|
clippy::needless_pass_by_value,
|
||||||
|
clippy::non_ascii_literal,
|
||||||
|
clippy::option_map_unwrap_or_else,
|
||||||
|
clippy::shadow_reuse,
|
||||||
|
clippy::struct_excessive_bools,
|
||||||
|
clippy::too_many_lines,
|
||||||
|
clippy::unseparated_literal_suffix,
|
||||||
|
clippy::wildcard_enum_match_arm,
|
||||||
|
clippy::wildcard_imports
|
||||||
|
)]
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
#[macro_use]
|
||||||
|
mod assert_matches;
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
mod errln;
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
mod err;
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
mod out;
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
mod outln;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
#[macro_use]
|
||||||
|
mod test_env;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test_env_builder;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod capture;
|
||||||
|
|
||||||
|
mod arguments;
|
||||||
|
mod bytes;
|
||||||
|
mod common;
|
||||||
|
mod consts;
|
||||||
|
mod env;
|
||||||
|
mod error;
|
||||||
|
mod file_error;
|
||||||
|
mod file_info;
|
||||||
|
mod file_path;
|
||||||
|
mod file_status;
|
||||||
|
mod files;
|
||||||
|
mod hasher;
|
||||||
|
mod host_port;
|
||||||
|
mod host_port_parse_error;
|
||||||
|
mod info;
|
||||||
|
mod infohash;
|
||||||
|
mod input;
|
||||||
|
mod input_stream;
|
||||||
|
mod input_target;
|
||||||
|
mod into_u64;
|
||||||
|
mod into_usize;
|
||||||
|
mod invariant;
|
||||||
|
mod lint;
|
||||||
|
mod linter;
|
||||||
|
mod magnet_link;
|
||||||
|
mod md5_digest;
|
||||||
|
mod metainfo;
|
||||||
|
mod metainfo_error;
|
||||||
|
mod mode;
|
||||||
|
mod options;
|
||||||
|
mod output_stream;
|
||||||
|
mod output_target;
|
||||||
|
mod piece_length_picker;
|
||||||
|
mod piece_list;
|
||||||
|
mod platform;
|
||||||
|
mod platform_interface;
|
||||||
|
mod print;
|
||||||
|
mod reckoner;
|
||||||
|
mod run;
|
||||||
|
mod sha1_digest;
|
||||||
|
mod shell;
|
||||||
|
mod sort_key;
|
||||||
|
mod sort_order;
|
||||||
|
mod sort_spec;
|
||||||
|
mod status;
|
||||||
|
mod step;
|
||||||
|
mod style;
|
||||||
|
mod subcommand;
|
||||||
|
mod table;
|
||||||
|
mod torrent_summary;
|
||||||
|
mod use_color;
|
||||||
|
mod verifier;
|
||||||
|
mod walker;
|
||||||
|
mod xor_args;
|
||||||
|
|
||||||
|
pub use run::run;
|
109
src/main.rs
109
src/main.rs
|
@ -1,110 +1,5 @@
|
||||||
#![deny(clippy::all, clippy::pedantic, clippy::restriction)]
|
|
||||||
#![allow(
|
|
||||||
clippy::else_if_without_else,
|
|
||||||
clippy::enum_glob_use,
|
|
||||||
clippy::float_arithmetic,
|
|
||||||
clippy::float_cmp,
|
|
||||||
clippy::implicit_return,
|
|
||||||
clippy::indexing_slicing,
|
|
||||||
clippy::integer_arithmetic,
|
|
||||||
clippy::integer_division,
|
|
||||||
clippy::large_enum_variant,
|
|
||||||
clippy::missing_docs_in_private_items,
|
|
||||||
clippy::needless_pass_by_value,
|
|
||||||
clippy::non_ascii_literal,
|
|
||||||
clippy::option_map_unwrap_or_else,
|
|
||||||
clippy::shadow_reuse,
|
|
||||||
clippy::too_many_lines,
|
|
||||||
clippy::unseparated_literal_suffix,
|
|
||||||
clippy::wildcard_enum_match_arm,
|
|
||||||
clippy::wildcard_imports,
|
|
||||||
clippy::struct_excessive_bools
|
|
||||||
)]
|
|
||||||
|
|
||||||
use crate::common::*;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
#[macro_use]
|
|
||||||
mod assert_matches;
|
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
mod errln;
|
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
mod err;
|
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
mod out;
|
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
mod outln;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
#[macro_use]
|
|
||||||
mod test_env;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod test_env_builder;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod capture;
|
|
||||||
|
|
||||||
mod arguments;
|
|
||||||
mod bytes;
|
|
||||||
mod common;
|
|
||||||
mod consts;
|
|
||||||
mod env;
|
|
||||||
mod error;
|
|
||||||
mod file_error;
|
|
||||||
mod file_info;
|
|
||||||
mod file_path;
|
|
||||||
mod file_status;
|
|
||||||
mod files;
|
|
||||||
mod hasher;
|
|
||||||
mod host_port;
|
|
||||||
mod host_port_parse_error;
|
|
||||||
mod info;
|
|
||||||
mod infohash;
|
|
||||||
mod input;
|
|
||||||
mod input_stream;
|
|
||||||
mod input_target;
|
|
||||||
mod into_u64;
|
|
||||||
mod into_usize;
|
|
||||||
mod invariant;
|
|
||||||
mod lint;
|
|
||||||
mod linter;
|
|
||||||
mod magnet_link;
|
|
||||||
mod md5_digest;
|
|
||||||
mod metainfo;
|
|
||||||
mod metainfo_error;
|
|
||||||
mod mode;
|
|
||||||
mod options;
|
|
||||||
mod output_stream;
|
|
||||||
mod output_target;
|
|
||||||
mod piece_length_picker;
|
|
||||||
mod piece_list;
|
|
||||||
mod platform;
|
|
||||||
mod platform_interface;
|
|
||||||
mod print;
|
|
||||||
mod reckoner;
|
|
||||||
mod sha1_digest;
|
|
||||||
mod shell;
|
|
||||||
mod sort_key;
|
|
||||||
mod sort_order;
|
|
||||||
mod sort_spec;
|
|
||||||
mod status;
|
|
||||||
mod step;
|
|
||||||
mod style;
|
|
||||||
mod subcommand;
|
|
||||||
mod table;
|
|
||||||
mod torrent_summary;
|
|
||||||
mod use_color;
|
|
||||||
mod verifier;
|
|
||||||
mod walker;
|
|
||||||
mod xor_args;
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
if let Err(code) = Env::main().status() {
|
if let Err(code) = imdl::run() {
|
||||||
process::exit(code);
|
std::process::exit(code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
22
src/run.rs
Normal file
22
src/run.rs
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
use crate::common::*;
|
||||||
|
|
||||||
|
/// Entry point into the IMDL binary.
|
||||||
|
///
|
||||||
|
/// Called by `main` in `main.rs`.
|
||||||
|
///
|
||||||
|
/// Constructs an `Env` using `Env::main`, containing the command line
|
||||||
|
/// arguments, the current working directory, a handle to standard error,
|
||||||
|
/// standard output, and standard input.
|
||||||
|
///
|
||||||
|
/// Calls `Env::status` which runs the program, prints error messages, and
|
||||||
|
/// returns a status code in case there was an error.
|
||||||
|
///
|
||||||
|
/// Errors
|
||||||
|
/// ------
|
||||||
|
///
|
||||||
|
/// In case of an error, a nonzero status code is returned. This status code can
|
||||||
|
/// be passed to `std::process::exit`, to exit the process and report its
|
||||||
|
/// failure to the system.
|
||||||
|
pub fn run() -> Result<(), i32> {
|
||||||
|
Env::main().status()
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
use super::*;
|
use crate::common::*;
|
||||||
|
|
||||||
use structopt::clap;
|
use structopt::clap;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user