aboutsummaryrefslogtreecommitdiff
path: root/mingling/src/parser/picker/builtin.rs
diff options
context:
space:
mode:
authorWeicao-CatilGrass <1992414357@qq.com>2026-05-23 17:44:17 +0800
committerWeicao-CatilGrass <1992414357@qq.com>2026-05-23 17:46:59 +0800
commit4836fceada0d9a87a82e1f2b011b3f9f5956dc4c (patch)
treef78abaff3cbb31781e6be42d97a25f4482415bd5 /mingling/src/parser/picker/builtin.rs
parente843405ecfee06ea158fb0070d4c70c2f228c82c (diff)
Add Default derive and Option Pickable implementation
Diffstat (limited to 'mingling/src/parser/picker/builtin.rs')
-rw-r--r--mingling/src/parser/picker/builtin.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/mingling/src/parser/picker/builtin.rs b/mingling/src/parser/picker/builtin.rs
index 9fbbfd1..e7a178d 100644
--- a/mingling/src/parser/picker/builtin.rs
+++ b/mingling/src/parser/picker/builtin.rs
@@ -60,6 +60,7 @@ impl Pickable for bool {
}
}
+/// Special: parses a size string (e.g. "10MB") into a `usize` representing the number of bytes.
impl Pickable for usize {
type Output = usize;
@@ -73,6 +74,7 @@ impl Pickable for usize {
}
}
+/// Special: parses a comma-separated list of size strings (e.g. "10MB,20KB") into a `Vec<usize>`.
impl Pickable for Vec<usize> {
type Output = Vec<usize>;
@@ -90,6 +92,7 @@ impl Pickable for Vec<usize> {
}
}
+/// Special: dumps the remaining arguments into an `Argument` struct.
impl Pickable for Argument {
type Output = Argument;
@@ -100,3 +103,13 @@ impl Pickable for Argument {
Some(args.dump_remains().into())
}
}
+
+/// Special: parses a single value of type `T` using the `Pickable` implementation for `T`, and wraps it in an `Option`.
+impl<T: Pickable<Output = T> + Default> Pickable for Option<T> {
+ type Output = Option<T>;
+
+ fn pick(args: &mut Argument, flag: mingling_core::Flag) -> Option<Self::Output> {
+ let r = T::pick(args, flag);
+ Some(r)
+ }
+}