summaryrefslogtreecommitdiff
path: root/mingling/src/parser/picker/builtin.rs
diff options
context:
space:
mode:
Diffstat (limited to 'mingling/src/parser/picker/builtin.rs')
-rw-r--r--mingling/src/parser/picker/builtin.rs53
1 files changed, 53 insertions, 0 deletions
diff --git a/mingling/src/parser/picker/builtin.rs b/mingling/src/parser/picker/builtin.rs
new file mode 100644
index 0000000..0b1ce08
--- /dev/null
+++ b/mingling/src/parser/picker/builtin.rs
@@ -0,0 +1,53 @@
+use size::Size;
+
+use crate::parser::Pickable;
+
+impl Pickable for String {
+ type Output = String;
+
+ fn pick(args: &mut crate::parser::Argument, flag: mingling_core::Flag) -> Option<Self::Output> {
+ args.pick_argument(flag)
+ }
+}
+
+macro_rules! impl_pickable_for_number {
+ ($($t:ty),*) => {
+ $(
+ impl Pickable for $t {
+ type Output = $t;
+
+ fn pick(args: &mut crate::parser::Argument, flag: mingling_core::Flag) -> Option<Self::Output> {
+ let Some(picked) = args.pick_argument(flag) else {
+ return None;
+ };
+ picked.parse().ok()
+ }
+ }
+ )*
+ };
+}
+
+impl_pickable_for_number!(i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, f32, f64);
+
+impl Pickable for bool {
+ type Output = bool;
+
+ fn pick(args: &mut crate::parser::Argument, flag: mingling_core::Flag) -> Option<Self::Output> {
+ Some(args.pick_flag(flag))
+ }
+}
+
+impl Pickable for usize {
+ type Output = usize;
+
+ fn pick(args: &mut crate::parser::Argument, flag: mingling_core::Flag) -> Option<Self::Output> {
+ let Some(picked) = args.pick_argument(flag) else {
+ return None;
+ };
+ let size_parse = Size::from_str(picked.as_str());
+ match size_parse {
+ Ok(size) => Some(size.bytes() as usize),
+ Err(_) => None,
+ }
+ }
+}