i_splits

Crates.ioi_splits
lib.rsi_splits
version
sourcesrc
created_at2025-02-14 13:48:07.4943+00
updated_at2025-02-14 13:48:07.4943+00
descriptionMore ways to split your strs!
homepage
repository
max_upload_size
id1555608
Cargo.toml error:TOML parse error at line 19, column 1 | 19 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
RustyNova (RustyNova016)

documentation

README

i_splits

This crate add two string splitting methods:

  • split_i: Split the string in half at the occurence i of a pattern.

  • split_once_last: Split the string in half at the last occurence of a pattern.

This crate use no dependencies and no unsafe code. This comes at a compromise of having to return Strings instead of &strs, as well as only being able to pass &strs as patterns. This is due to the fact that the Pattern trait isn't stable yet in std.

Example

use i_splits::ISplitExt as _;

// split_i

let v = "To show you the power of i_split, I cut that sentence in half!".split_i(", ", 1);
assert_eq!(v, Some(("To show you the power of i_split".to_string(), "I cut that sentence in half!".to_string())));

let v = "cookie|lolipop|muffin|pancake".split_i("|", 2);
assert_eq!(v, Some(("cookie|lolipop".to_string(), "muffin|pancake".to_string())));

let v = "No splits? That's a `None` for you".split_i("!", 2);
assert_eq!(v, None);

let v = "Don't go too far either!".split_i(" ", 10);
assert_eq!(v, None);

// split_once_last

let v = "To show you the power of i_split, I cut that sentence in half!".split_once_last(", ");
assert_eq!(v, Some(("To show you the power of i_split".to_string(), "I cut that sentence in half!".to_string())));

let v = "cookie|lolipop|muffin|pancake".split_once_last("|");
assert_eq!(v, Some(("cookie|lolipop|muffin".to_string(), "pancake".to_string())));
Commit count: 0

cargo fmt