From b4bbe8a7733ce8f45cbd0d9b337ce3cb29f75e98 Mon Sep 17 00:00:00 2001 From: SoniEx2 Date: Sat, 4 Dec 2021 18:22:12 -0300 Subject: Add helpers for integer and float arguments --- src/args.rs | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'src') 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> { pub _ty: PhantomData, } +/// Helper to create an integer argument with values not bounded by a range. +/// +/// # Examples +/// +/// ```rust +/// use ::iosonism::args::integer; +/// +/// let argtype = integer::(); +/// ``` +pub fn integer() -> IntegerArgumentType { + 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>( + range: R, +) -> IntegerArgumentType { + IntegerArgumentType { + range: range, + _ty: PhantomData, + } +} + /// An `ArgumentType` for integer types. impl ArgumentType for IntegerArgumentType where @@ -218,6 +252,40 @@ pub struct FloatArgumentType> { pub _ty: PhantomData, } +/// Helper to create a float argument with values not bounded by a range. +/// +/// # Examples +/// +/// ```rust +/// use ::iosonism::args::float; +/// +/// let argtype = float::(); +/// ``` +pub fn float() -> FloatArgumentType { + 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>( + range: R, +) -> FloatArgumentType { + FloatArgumentType { + range: range, + _ty: PhantomData, + } +} + /// An `ArgumentType` for float types. impl ArgumentType for FloatArgumentType where -- cgit 1.4.1