#str #split #string #optional

split-optional

It split from a source str to Option<&'a str> per an element

1 stable release

1.0.0 Sep 11, 2022

#2164 in Rust patterns

MIT license

5KB
102 lines

split-optional

It split from a source str to Option<&'a str> per an element.

Usage | Example

fn main()
{
 const SOME_INPUT: &str = "aaa,bbb,ccc";

 // (Some("aaa"), Some("bbb,ccc"))
 let result = split_optional::split2(SOME_INPUT, ",");
 println!("{result:?}");

 // (Some("aaa"), Some("bbb"), Some("ccc"))
 let result = split_optional::split3(SOME_INPUT, ",");
 println!("{result:?}");

 // (Some("aaa"), Some("bbb"), Some("ccc"), None)
 let result = split_optional::split4(SOME_INPUT, ",");
 println!("{result:?}");

 // (Some("aaa"), Some("bbb"), Some("ccc"), None, None)
 let result = split_optional::split5(SOME_INPUT, ",");
 println!("{result:?}");
}

License

Author

No runtime deps