Compare commits
2 commits
main
...
restructur
Author | SHA1 | Date | |
---|---|---|---|
a8c8b5b3db | |||
0124b34486 |
13 changed files with 71 additions and 91 deletions
11
Cargo.toml
11
Cargo.toml
|
@ -17,12 +17,9 @@ all-features = true
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
prim = ["number", "bool"]
|
|
||||||
number = []
|
|
||||||
bool = []
|
|
||||||
vec = []
|
|
||||||
tuple = []
|
|
||||||
low-level = []
|
low-level = []
|
||||||
|
aggs = []
|
||||||
|
structs = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
||||||
|
@ -31,8 +28,8 @@ maintenance = { status = "actively-developed" }
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "calc"
|
name = "calc"
|
||||||
required-features = ["vec", "number"]
|
required-features = ["structs"]
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "dotenv"
|
name = "dotenv"
|
||||||
required-features = ["vec", "tuple", "low-level"]
|
required-features = ["structs", "low-level"]
|
||||||
|
|
2
src/agg.rs
Normal file
2
src/agg.rs
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
//! This module will contain aggregate functions (Sum, Product, etc)
|
||||||
|
//!
|
19
src/core.rs
19
src/core.rs
|
@ -1,25 +1,6 @@
|
||||||
//! Contains the ``EString`` type, as well as the basic implementation of conversions to
|
//! Contains the ``EString`` type, as well as the basic implementation of conversions to
|
||||||
//! string types
|
//! string types
|
||||||
//!
|
//!
|
||||||
#[cfg(any(feature = "number", feature = "bool"))]
|
|
||||||
pub mod prim;
|
|
||||||
#[cfg(any(feature = "number", feature = "bool"))]
|
|
||||||
pub use prim::*;
|
|
||||||
|
|
||||||
#[cfg(feature = "vec")]
|
|
||||||
pub mod vec;
|
|
||||||
#[cfg(feature = "vec")]
|
|
||||||
pub use vec::*;
|
|
||||||
|
|
||||||
#[cfg(feature = "tuple")]
|
|
||||||
pub mod tuple;
|
|
||||||
#[cfg(feature = "tuple")]
|
|
||||||
pub use tuple::*;
|
|
||||||
|
|
||||||
#[cfg(feature = "low-level")]
|
|
||||||
pub mod low;
|
|
||||||
#[cfg(feature = "low-level")]
|
|
||||||
pub use low::*;
|
|
||||||
|
|
||||||
use crate::ParseError;
|
use crate::ParseError;
|
||||||
use std::convert::Infallible;
|
use std::convert::Infallible;
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
//! Contains the implementations to primitive types (number, boolean)
|
|
||||||
//!
|
|
||||||
//! **NOTE**: Require the enabling of the same-name features
|
|
||||||
//!
|
|
||||||
|
|
||||||
#[cfg(feature = "bool")]
|
|
||||||
mod bool;
|
|
||||||
#[cfg(feature = "bool")]
|
|
||||||
pub use self::bool::*;
|
|
||||||
|
|
||||||
#[cfg(feature = "number")]
|
|
||||||
mod number;
|
|
||||||
#[cfg(feature = "number")]
|
|
||||||
pub use self::number::*;
|
|
18
src/lib.rs
18
src/lib.rs
|
@ -31,8 +31,24 @@
|
||||||
#![allow(clippy::module_name_repetitions)]
|
#![allow(clippy::module_name_repetitions)]
|
||||||
#![warn(missing_docs)]
|
#![warn(missing_docs)]
|
||||||
|
|
||||||
pub mod core;
|
|
||||||
mod error;
|
mod error;
|
||||||
|
|
||||||
|
pub mod core;
|
||||||
|
pub mod std;
|
||||||
|
|
||||||
|
#[cfg(feature = "aggs")]
|
||||||
|
pub mod agg;
|
||||||
|
#[cfg(feature = "aggs")]
|
||||||
|
pub use agg::*;
|
||||||
|
|
||||||
|
#[cfg(feature = "low-level")]
|
||||||
|
pub mod low;
|
||||||
|
#[cfg(feature = "low-level")]
|
||||||
|
pub use low::*;
|
||||||
|
#[cfg(feature = "structs")]
|
||||||
|
pub mod structs;
|
||||||
|
#[cfg(feature = "structs")]
|
||||||
|
pub use structs::*;
|
||||||
|
|
||||||
pub use crate::core::*;
|
pub use crate::core::*;
|
||||||
pub use crate::error::ParseError;
|
pub use crate::error::ParseError;
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
use crate::core::EString;
|
use crate::core::EString;
|
||||||
|
|
||||||
//===========================================================================//
|
|
||||||
// TRIM //
|
|
||||||
//===========================================================================//
|
|
||||||
|
|
||||||
/// Wrapper that allow to trim substring before continue
|
/// Wrapper that allow to trim substring before continue
|
||||||
///
|
///
|
||||||
/// **NOTE**: Required the enabling of the `low-level` feature.
|
/// **NOTE**: Required the enabling of the `low-level` feature.
|
8
src/std.rs
Normal file
8
src/std.rs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
//! Contains implementations for standard types (`bool`, numbers, `Option`, etc.)
|
||||||
|
//!
|
||||||
|
|
||||||
|
mod bool;
|
||||||
|
mod number;
|
||||||
|
|
||||||
|
pub use self::bool::*;
|
||||||
|
pub use number::*;
|
|
@ -4,7 +4,6 @@ use crate::core::EString;
|
||||||
macro_rules! from_env_string_numbers_impl {
|
macro_rules! from_env_string_numbers_impl {
|
||||||
($($ty:ty),+$(,)?) => {
|
($($ty:ty),+$(,)?) => {
|
||||||
$(
|
$(
|
||||||
#[cfg(feature = "number")]
|
|
||||||
impl TryFrom<EString> for $ty {
|
impl TryFrom<EString> for $ty {
|
||||||
type Error = <$ty as std::str::FromStr>::Err;
|
type Error = <$ty as std::str::FromStr>::Err;
|
||||||
|
|
10
src/structs.rs
Normal file
10
src/structs.rs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
//! Contains the predefined types (``SepVec``, ``Pair``, etc.)
|
||||||
|
//!
|
||||||
|
//! **NOTE**: Require the enabling the `structs` feature.
|
||||||
|
//!
|
||||||
|
|
||||||
|
mod pair;
|
||||||
|
mod sep_vec;
|
||||||
|
|
||||||
|
pub use pair::*;
|
||||||
|
pub use sep_vec::*;
|
|
@ -1,6 +1,4 @@
|
||||||
//! Contains the implementations to tuple type
|
//! Contains the implementations to pair tuple type
|
||||||
//!
|
|
||||||
//! **NOTE**: Require the enabling of the `tuple` features
|
|
||||||
//!
|
//!
|
||||||
|
|
||||||
use crate::core::EString;
|
use crate::core::EString;
|
||||||
|
@ -87,6 +85,7 @@ where
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::structs::SepVec;
|
||||||
|
|
||||||
type EqPair<A, B> = Pair<A, '=', B>;
|
type EqPair<A, B> = Pair<A, '=', B>;
|
||||||
|
|
||||||
|
@ -108,24 +107,17 @@ mod tests {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "number")]
|
type LineVec<T> = SepVec<T, '\n'>;
|
||||||
mod vec {
|
|
||||||
use crate::SepVec;
|
|
||||||
|
|
||||||
use super::*;
|
#[test]
|
||||||
|
fn should_parse_vec_of_pairs() {
|
||||||
type LineVec<T> = SepVec<T, '\n'>;
|
let estr = EString::from(
|
||||||
|
"foo=bar
|
||||||
#[test]
|
|
||||||
fn should_parse_vec_of_pairs() {
|
|
||||||
let estr = EString::from(
|
|
||||||
"foo=bar
|
|
||||||
hello=bar",
|
hello=bar",
|
||||||
);
|
);
|
||||||
match estr.parse::<LineVec<EqPair<&str, &str>>>() {
|
match estr.parse::<LineVec<EqPair<&str, &str>>>() {
|
||||||
Ok(res) => assert_eq!(res, SepVec(vec![Pair("foo", "bar"), Pair("hello", "bar"),])),
|
Ok(res) => assert_eq!(res, SepVec(vec![Pair("foo", "bar"), Pair("hello", "bar"),])),
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,7 +1,5 @@
|
||||||
//! Contains the implementations to vec type
|
//! Contains the implementations to vec type
|
||||||
//!
|
//!
|
||||||
//! **NOTE**: Require the enabling of the `vec` features
|
|
||||||
//!
|
|
||||||
|
|
||||||
use crate::core::EString;
|
use crate::core::EString;
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
|
@ -78,6 +76,7 @@ where
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::ParseError;
|
||||||
|
|
||||||
const COMMA: char = ',';
|
const COMMA: char = ',';
|
||||||
const SEMI: char = ';';
|
const SEMI: char = ';';
|
||||||
|
@ -122,29 +121,23 @@ d,e";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "number")]
|
#[test]
|
||||||
mod numbers {
|
fn should_parse_into_num_vec() {
|
||||||
use super::*;
|
let estr = EString::from("1,2,3,4,5");
|
||||||
use crate::ParseError;
|
match estr.parse::<CommaVec<i32>>() {
|
||||||
|
Ok(res) => assert_eq!(*res, vec![1, 2, 3, 4, 5]),
|
||||||
|
_ => unreachable!(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn should_parse_into_num_vec() {
|
fn should_throw_parse_vec_error() {
|
||||||
let estr = EString::from("1,2,3,4,5");
|
let estr = EString::from("1,2,3,4,5");
|
||||||
match estr.parse::<CommaVec<i32>>() {
|
match estr.parse::<SemiVec<i32>>() {
|
||||||
Ok(res) => assert_eq!(*res, vec![1, 2, 3, 4, 5]),
|
Err(ParseError(orig)) => {
|
||||||
_ => unreachable!(),
|
assert_eq!(orig, String::from("1,2,3,4,5"));
|
||||||
};
|
}
|
||||||
}
|
_ => unreachable!(),
|
||||||
|
};
|
||||||
#[test]
|
|
||||||
fn should_throw_parse_vec_error() {
|
|
||||||
let estr = EString::from("1,2,3,4,5");
|
|
||||||
match estr.parse::<SemiVec<i32>>() {
|
|
||||||
Err(ParseError(orig)) => {
|
|
||||||
assert_eq!(orig, String::from("1,2,3,4,5"));
|
|
||||||
}
|
|
||||||
_ => unreachable!(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in a new issue