diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-08-17 04:05:41 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-08-17 04:05:41 +0800 |
| commit | aa251efb87b561f62266628f06ad341253fbbdc5 (patch) | |
| tree | 7d2cc2f34f3e4a7282d8d6f0ec0f5ae4bfc87002 /examples/example-enum-tag | |
| parent | c23c590330af83afb6e146bcd9b0a274b3689d22 (diff) | |
refactor!: remove legacy parser feature and migrate to picker
The legacy `parser` feature and its module tree (`mingling::parser`,
`Argument`, `Picker`, `Pickable`, etc.) have been fully removed and
replaced by the `picker` feature powered by `arg-picker`.
BREAKING CHANGE: Remove `parser` feature and use `picker` instead.
Migration guide: Replace `features = ["parser"]` with
`features = ["picker"]` and update API usage per the provided table.
Diffstat (limited to 'examples/example-enum-tag')
| -rw-r--r-- | examples/example-enum-tag/Cargo.lock | 25 | ||||
| -rw-r--r-- | examples/example-enum-tag/Cargo.toml | 2 | ||||
| -rw-r--r-- | examples/example-enum-tag/src/main.rs | 40 |
3 files changed, 50 insertions, 17 deletions
diff --git a/examples/example-enum-tag/Cargo.lock b/examples/example-enum-tag/Cargo.lock index 868af79..492d708 100644 --- a/examples/example-enum-tag/Cargo.lock +++ b/examples/example-enum-tag/Cargo.lock @@ -3,6 +3,23 @@ version = 4 [[package]] +name = "arg-picker" +version = "0.2.0" +dependencies = [ + "arg-picker-macros", + "just_fmt 0.2.0", +] + +[[package]] +name = "arg-picker-macros" +version = "0.2.0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.118", +] + +[[package]] name = "equivalent" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -86,9 +103,9 @@ dependencies = [ name = "mingling" version = "0.5.0" dependencies = [ + "arg-picker", "mingling_core", "mingling_macros", - "size", ] [[package]] @@ -167,12 +184,6 @@ dependencies = [ ] [[package]] -name = "size" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b6709c7b6754dca1311b3c73e79fcce40dd414c782c66d88e8823030093b02b" - -[[package]] name = "syn" version = "2.0.118" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/examples/example-enum-tag/Cargo.toml b/examples/example-enum-tag/Cargo.toml index 9c0a0ff..489f401 100644 --- a/examples/example-enum-tag/Cargo.toml +++ b/examples/example-enum-tag/Cargo.toml @@ -8,7 +8,7 @@ path = "../../mingling" features = [ "comp", - "parser" + "picker" ] [workspace] diff --git a/examples/example-enum-tag/src/main.rs b/examples/example-enum-tag/src/main.rs index 2966036..c7fb502 100644 --- a/examples/example-enum-tag/src/main.rs +++ b/examples/example-enum-tag/src/main.rs @@ -16,8 +16,10 @@ //! ``` use mingling::{ - macros::suggest_enum, parser::PickableEnum, prelude::*, EnumTag, Grouped, ShellContext, - Suggest, + EnumTag, Grouped, ShellContext, Suggest, + macros::suggest_enum, + picker::{PickerArgResult, SinglePickable}, + prelude::*, }; use std::io::Write; @@ -57,9 +59,7 @@ pub enum ProgrammingLanguages { #[enum_desc("A general-purpose programming language with clean syntax, known for readability")] Python, - #[enum_desc( - "An object-oriented scripting language, famous for its concise and elegant syntax" - )] + #[enum_desc("An object-oriented scripting language, famous for its concise and elegant syntax")] Ruby, #[default] @@ -68,9 +68,31 @@ pub enum ProgrammingLanguages { } // --------- IMPORTANT --------- -// Implement the PickableEnum trait for ProgrammingLanguages, -// so that `Picker` can parse this enum -impl PickableEnum for ProgrammingLanguages {} +// NOTE: Due to the migration from the legacy `parser` to `picker`, the `EnumTag` -> `Picker` path +// is not yet complete, so a manual implementation is used for now. +// Once that path is complete, `#[derive(EnumTag)]` can automatically implement `SinglePickable`, +// replacing this manual implementation. +impl SinglePickable for ProgrammingLanguages { + fn pick_single(str: Option<&str>) -> PickerArgResult<Self> { + let Some(str) = str else { + return PickerArgResult::NotFound; + }; + let lang = match str.to_lowercase().as_str() { + "c" => Self::C, + "c++" | "cpp" => Self::CPlusPlus, + "c#" | "csharp" => Self::Csharp, + "java" => Self::Java, + "javascript" | "js" => Self::JavaScript, + "kotlin" => Self::Kotlin, + "ocaml" => Self::OCaml, + "python" => Self::Python, + "ruby" => Self::Ruby, + "rust" => Self::Rust, + _ => return PickerArgResult::NotFound, + }; + PickerArgResult::Parsed(lang) + } +} // --------- IMPORTANT --------- dispatcher!("lang-select", EntryLanguageSelection); @@ -78,7 +100,7 @@ dispatcher!("lang-select", EntryLanguageSelection); #[chain] fn handle_language_selection(args: EntryLanguageSelection) -> Next { // You can use Picker to directly parse ProgrammingLanguages - let lang: ProgrammingLanguages = args.pick(()).unpack(); + let lang: ProgrammingLanguages = args.pick_or_default(&arg![ProgrammingLanguages]).unwrap(); lang.into() } |
