summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorSoniEx2 <endermoneymod@gmail.com>2021-12-04 18:22:12 -0300
committerSoniEx2 <endermoneymod@gmail.com>2021-12-04 18:22:12 -0300
commitb4bbe8a7733ce8f45cbd0d9b337ce3cb29f75e98 (patch)
treee2ab58700e8c6814308b5d9568d13ff3acbee397 /src
parent36395c7437218b86c832cc041f7a58f325a007bb (diff)
Add helpers for integer and float arguments
Diffstat (limited to 'src')
-rw-r--r--src/args.rs68
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