aboutsummaryrefslogtreecommitdiff
path: root/examples/example-custom-pickable
diff options
context:
space:
mode:
Diffstat (limited to 'examples/example-custom-pickable')
-rw-r--r--examples/example-custom-pickable/Cargo.lock223
-rw-r--r--examples/example-custom-pickable/Cargo.toml11
-rw-r--r--examples/example-custom-pickable/page.toml10
-rw-r--r--examples/example-custom-pickable/src/main.rs130
-rw-r--r--examples/example-custom-pickable/test.toml17
5 files changed, 0 insertions, 391 deletions
diff --git a/examples/example-custom-pickable/Cargo.lock b/examples/example-custom-pickable/Cargo.lock
deleted file mode 100644
index 3aa6236..0000000
--- a/examples/example-custom-pickable/Cargo.lock
+++ /dev/null
@@ -1,223 +0,0 @@
-# This file is automatically @generated by Cargo.
-# It is not intended for manual editing.
-version = 4
-
-[[package]]
-name = "equivalent"
-version = "1.0.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
-
-[[package]]
-name = "example-custom-pickable"
-version = "0.1.0"
-dependencies = [
- "mingling",
-]
-
-[[package]]
-name = "hashbrown"
-version = "0.17.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
-
-[[package]]
-name = "indexmap"
-version = "2.14.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9"
-dependencies = [
- "equivalent",
- "hashbrown",
-]
-
-[[package]]
-name = "just_fmt"
-version = "0.2.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6170dccbc3ea15dfb7f2da964097f814aba1dd8f746d4ffc56f33245c38e6d96"
-
-[[package]]
-name = "memchr"
-version = "2.8.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
-
-[[package]]
-name = "might_be_async"
-version = "0.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "eca871cea620b07bd2e6da0c883891a25bead698c43a9ab64b0fd663a7a78d5f"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn 2.0.118",
- "toml",
-]
-
-[[package]]
-name = "mingling"
-version = "0.5.0"
-dependencies = [
- "mingling_core",
- "mingling_macros",
- "size",
-]
-
-[[package]]
-name = "mingling_core"
-version = "0.5.0"
-dependencies = [
- "just_fmt",
- "might_be_async",
-]
-
-[[package]]
-name = "mingling_macros"
-version = "0.5.0"
-dependencies = [
- "just_fmt",
- "proc-macro2",
- "quote",
- "syn 2.0.118",
-]
-
-[[package]]
-name = "proc-macro2"
-version = "1.0.106"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
-dependencies = [
- "unicode-ident",
-]
-
-[[package]]
-name = "quote"
-version = "1.0.46"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "dfbc457d0c7a0759a614551b11a6409e5951f6c7537be1f1b7682b9ae9230368"
-dependencies = [
- "proc-macro2",
-]
-
-[[package]]
-name = "serde"
-version = "1.0.229"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
-dependencies = [
- "serde_core",
-]
-
-[[package]]
-name = "serde_core"
-version = "1.0.229"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
-dependencies = [
- "serde_derive",
-]
-
-[[package]]
-name = "serde_derive"
-version = "1.0.229"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn 3.0.3",
-]
-
-[[package]]
-name = "serde_spanned"
-version = "0.6.9"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bf41e0cfaf7226dca15e8197172c295a782857fcb97fad1808a166870dee75a3"
-dependencies = [
- "serde",
-]
-
-[[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"
-checksum = "1b9ae57f904213ebb649ce6895b8a66c66f0203b9319718f69a5612a065b1422"
-dependencies = [
- "proc-macro2",
- "quote",
- "unicode-ident",
-]
-
-[[package]]
-name = "syn"
-version = "3.0.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "53e9bae58849f64dfa4f5d5ae372c8341f7305f82a3868709269343628b659a3"
-dependencies = [
- "proc-macro2",
- "quote",
- "unicode-ident",
-]
-
-[[package]]
-name = "toml"
-version = "0.8.23"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362"
-dependencies = [
- "serde",
- "serde_spanned",
- "toml_datetime",
- "toml_edit",
-]
-
-[[package]]
-name = "toml_datetime"
-version = "0.6.11"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c"
-dependencies = [
- "serde",
-]
-
-[[package]]
-name = "toml_edit"
-version = "0.22.27"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a"
-dependencies = [
- "indexmap",
- "serde",
- "serde_spanned",
- "toml_datetime",
- "toml_write",
- "winnow",
-]
-
-[[package]]
-name = "toml_write"
-version = "0.1.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801"
-
-[[package]]
-name = "unicode-ident"
-version = "1.0.24"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
-
-[[package]]
-name = "winnow"
-version = "0.7.15"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945"
-dependencies = [
- "memchr",
-]
diff --git a/examples/example-custom-pickable/Cargo.toml b/examples/example-custom-pickable/Cargo.toml
deleted file mode 100644
index 9324bd6..0000000
--- a/examples/example-custom-pickable/Cargo.toml
+++ /dev/null
@@ -1,11 +0,0 @@
-[package]
-name = "example-custom-pickable"
-version = "0.1.0"
-edition = "2024"
-
-[dependencies.mingling]
-path = "../../mingling"
-
-features = ["parser", "extras"]
-
-[workspace]
diff --git a/examples/example-custom-pickable/page.toml b/examples/example-custom-pickable/page.toml
deleted file mode 100644
index 1c3bfa0..0000000
--- a/examples/example-custom-pickable/page.toml
+++ /dev/null
@@ -1,10 +0,0 @@
-[example]
-id = "example-custom-pickable"
-name = "Custom Pickable"
-icon = "🎯"
-category = "parsing"
-desc = """
-Shows how to implement the `Pickable` trait on custom types for seamless extraction from CLI arguments via Picker.
-"""
-tags = ["Pickable", "custom"]
-files = ["src/main.rs", "Cargo.toml"]
diff --git a/examples/example-custom-pickable/src/main.rs b/examples/example-custom-pickable/src/main.rs
deleted file mode 100644
index 8265b09..0000000
--- a/examples/example-custom-pickable/src/main.rs
+++ /dev/null
@@ -1,130 +0,0 @@
-//! Example Custom Pickable
-//!
-//! > This example demonstrates how to use the Pickable trait to add parsing for your types
-//!
-//! Run:
-//! ```bash
-//! cargo run --manifest-path examples/example-custom-pickable/Cargo.toml --quiet -- connect 127.0.0.1:5012
-//! cargo run --manifest-path examples/example-custom-pickable/Cargo.toml --quiet -- connect 127.0.0.1
-//! ```
-//!
-//! Output:
-//! ```plaintext
-//! Connected to "127.0.0.1:5012"
-//! Failed to parse address
-//! ```
-
-use mingling::{macros::route, parser::Pickable, prelude::*, Grouped};
-use std::io::Write;
-
-// Define types that can be recognized by Mingling
-// ________________________ `Pickable` trait needs to implement Default
-// / ________ The Grouped derive macro registers an ID for this type
-// | / Mingling uses this ID to identify the type
-// vvvvvvv vvvvvvv
-#[derive(Debug, Default, Clone, Grouped)]
-pub struct Address {
- pub ip: [u8; 4],
- pub port: u16,
-}
-
-// --------- IMPORTANT ---------
-impl Pickable for Address {
- type Output = Address;
- fn pick(args: &mut mingling::parser::Argument, flag: mingling::Flag) -> Option<Self::Output> {
- // Extract the raw string from Argument using the Flag
- let raw: String = args.pick_argument(flag)?.clone();
-
- // Use TryFrom to parse the address
- Address::try_from(raw).ok()
- }
-}
-// --------- IMPORTANT ---------
-
-dispatcher!("connect", EntryConnect);
-pack!(ErrorParseAddressFailed = ());
-
-#[chain]
-fn handle_connect(prev: EntryConnect) -> Next {
- let connect: Address =
- route! { prev.pick_or_route((), ErrorParseAddressFailed::default()).unpack() };
- connect.to_chain()
-}
-
-/// Renders the connected address.
-#[renderer]
-pub fn render_address(addr: Address) -> RenderResult {
- let mut render_result = RenderResult::new();
- write!(render_result, "Connected to \"{}\"", addr).ok();
- render_result
-}
-
-/// Renders the error message when address parsing fails.
-#[renderer]
-pub fn render_error_parse_address_failed(_: ErrorParseAddressFailed) -> RenderResult {
- let mut render_result = RenderResult::new();
- write!(render_result, "Failed to parse address").ok();
- render_result
-}
-
-gen_program!();
-
-fn main() {
- ThisProgram::new().exec_and_exit();
-}
-
-// Address conversion
-
-impl TryFrom<String> for Address {
- type Error = String;
-
- fn try_from(raw: String) -> Result<Self, Self::Error> {
- // Expected format: "192.168.1.1:8080"
- let parts: Vec<&str> = raw.split(':').collect();
- if parts.len() != 2 {
- return Err("Invalid format: expected 'IP:PORT'".to_string());
- }
-
- let ip_str = parts[0];
- let port_str = parts[1];
-
- // Parse IP address (4 octets separated by dots)
- let ip_parts: Vec<&str> = ip_str.split('.').collect();
- if ip_parts.len() != 4 {
- return Err("Invalid IP address format".to_string());
- }
-
- let mut ip = [0u8; 4];
- for (i, part) in ip_parts.iter().enumerate() {
- ip[i] = part
- .parse::<u8>()
- .map_err(|_| format!("Invalid IP octet: {part}"))?;
- }
-
- // Parse port
- let port = port_str
- .parse::<u16>()
- .map_err(|_| format!("Invalid port: {port_str}"))?;
-
- Ok(Address { ip, port })
- }
-}
-
-impl From<Address> for String {
- fn from(addr: Address) -> String {
- format!(
- "{}.{}.{}.{}:{}",
- addr.ip[0], addr.ip[1], addr.ip[2], addr.ip[3], addr.port
- )
- }
-}
-
-impl std::fmt::Display for Address {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- write!(
- f,
- "{}.{}.{}.{}:{}",
- self.ip[0], self.ip[1], self.ip[2], self.ip[3], self.port
- )
- }
-}
diff --git a/examples/example-custom-pickable/test.toml b/examples/example-custom-pickable/test.toml
deleted file mode 100644
index 8fc20eb..0000000
--- a/examples/example-custom-pickable/test.toml
+++ /dev/null
@@ -1,17 +0,0 @@
-[[runs]]
-input = [ "connect", "192.168.1.1:8080" ]
-
-expect.exit-code = 0
-expect.result = "Connected to \"192.168.1.1:8080\""
-
-[[runs]]
-input = [ "connect" ]
-
-expect.exit-code = 0
-expect.result = "Failed to parse address"
-
-[[runs]]
-input = [ "connect", "invalid" ]
-
-expect.exit-code = 0
-expect.result = "Failed to parse address"