Skip to content

Commit

Permalink
Add Strsplit project (#19)
Browse files Browse the repository at this point in the history
A project targeting lifetimes in rust following [Crust of Rust: Lifetime
Annotations](https://www.youtube.com/watch?v=rAl-9HwD858)
  • Loading branch information
ishaan26 authored Oct 2, 2024
2 parents 81427b0 + ffccd28 commit 070198e
Show file tree
Hide file tree
Showing 3 changed files with 348 additions and 7 deletions.
49 changes: 47 additions & 2 deletions zung_mini/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
//! Mini rust projects that target specific features of rust
pub mod progbar;
pub mod strsplit;

use clap::{Args, Subcommand};
use progbar::ProgBarExt;
use strsplit::StrsplitExt;

/// An example Clap Argument builder. Install the [`zung`](https://crates.io/crates/zung) crate and
/// run `zung mini progbar` to see what options are available
Expand All @@ -24,19 +26,51 @@ enum MiniCommands {
#[command(subcommand)]
command: ProgBarCommands,
},

/// Perform splitting functions over a string.
Strsplit {
#[command(subcommand)]
command: StrsplitCommands,
},
}

#[derive(Clone, Subcommand, Debug)]
#[command(arg_required_else_help = true)]
enum StrsplitCommands {
/// Split the provided string on the provided needle.
Split {
/// The needle to be fond in the haystack.
#[arg(short, long)]
needle: String,

/// The haystack to find the needle in.
#[arg(short, long)]
string: String,
},

/// Split the provided string until the needle occurs in the String.
Until {
/// The needle to be fond in the haystack.
#[arg(short, long)]
needle: String,

/// The haystack to find the needle in.
#[arg(short, long)]
string: String,
},
}

#[derive(Clone, Subcommand, Debug)]
#[command(arg_required_else_help = true)]
enum ProgBarCommands {
/// Runs the progbar on an simulated infinite loop.
/// Runs the progbar on a simulated infinite loop.
UnBounded {
/// Custom message to display along with the spinner.
#[arg(short, long, default_value_t = String::from("Simulating Loading..."))]
message: String,
},

/// Runs the progbar on an simulated loop having len of iter_count.
/// Runs the progbar on a simulated loop having len of iter_count.
Bounded {
/// Custom starting delimiter for the loading bar.
#[arg(long, default_value_t = String::from("["))]
Expand Down Expand Up @@ -87,6 +121,17 @@ impl MiniArgs {
}
}
}

MiniCommands::Strsplit { command } => match command {
StrsplitCommands::Split { needle, string } => {
let result = string.strsplit(&needle).into_vec();
println!("{:?}", result);
}
StrsplitCommands::Until { needle, string } => {
let result = string.till_needle(needle);
println!("{:?}", result);
}
},
}
}
}
10 changes: 5 additions & 5 deletions zung_mini/src/progbar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
//! # Features
//!
//! - **Easy to use**: The [`.progbar()`](ProgBarExt::progbar()) method can be applied to any
//! iterator, making progress tracking effortless.
//! iterator, making progress tracking effortless.
//! - **Bounded & Unbounded Progress Bars**: Automatically handles both finite and infinite
//! iterators. Bounded bars can display percentages, while unbounded bars display the progress
//! incrementally.
//! iterators. Bounded bars can display percentages, while unbounded bars display the progress
//! incrementally.
//! - **Customizable Styles**: Modify the progress bar's appearance with custom delimiters and bar
//! styles.
//! styles.
//! - **Terminal Display**: The library displays a live progress bar in the terminal, updating in
//! real-time during iteration.
//! real-time during iteration.
//!
//! # Example Usage
//!
Expand Down
Loading

0 comments on commit 070198e

Please sign in to comment.