diff options
Diffstat (limited to 'src/args.rs')
-rw-r--r-- | src/args.rs | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/args.rs b/src/args.rs index 2a9bc28..8647ea7 100644 --- a/src/args.rs +++ b/src/args.rs @@ -177,6 +177,40 @@ pub struct IntegerArgumentType<T, R: RangeBounds<T>> { pub _ty: PhantomData<T>, } +/// Helper to create an integer argument with values not bounded by a range. +/// +/// # Examples +/// +/// ```rust +/// use ::iosonism::args::integer; +/// +/// let argtype = integer::<i32>(); +/// ``` +pub fn integer<T>() -> IntegerArgumentType<T, ::std::ops::RangeFull> { + IntegerArgumentType { + range: .., + _ty: PhantomData, + } +} + +/// Helper to create an integer argument with values bounded by a range. +/// +/// # Examples +/// +/// ```rust +/// use ::iosonism::args::bounded_integer; +/// +/// let argtype = bounded_integer(0..100i32); +/// ``` +pub fn bounded_integer<T, R: RangeBounds<T>>( + range: R, +) -> IntegerArgumentType<T, R> { + IntegerArgumentType { + range: range, + _ty: PhantomData, + } +} + /// An `ArgumentType` for integer types. impl<S, E, T, R> ArgumentType<S, E> for IntegerArgumentType<T, R> where @@ -218,6 +252,40 @@ pub struct FloatArgumentType<T, R: RangeBounds<T>> { pub _ty: PhantomData<T>, } +/// Helper to create a float argument with values not bounded by a range. +/// +/// # Examples +/// +/// ```rust +/// use ::iosonism::args::float; +/// +/// let argtype = float::<f32>(); +/// ``` +pub fn float<T>() -> FloatArgumentType<T, ::std::ops::RangeFull> { + FloatArgumentType { + range: .., + _ty: PhantomData, + } +} + +/// Helper to create a float argument with values bounded by a range. +/// +/// # Examples +/// +/// ```rust +/// use ::iosonism::args::bounded_float; +/// +/// let argtype = bounded_float(0.0..100f32); +/// ``` +pub fn bounded_float<T, R: RangeBounds<T>>( + range: R, +) -> FloatArgumentType<T, R> { + FloatArgumentType { + range: range, + _ty: PhantomData, + } +} + /// An `ArgumentType` for float types. impl<S, E, T, R> ArgumentType<S, E> for FloatArgumentType<T, R> where |