split-char-from-str 0.0.0

A small utility to split a string into the first or last character (type `char`) and the rest (type `&str`)
Documentation
  • Coverage
  • 100%
    6 out of 6 items documented5 out of 6 items with examples
  • Size
  • Source code size: 7.91 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 661.97 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • KSXGitHub/split-char-from-str
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • KSXGitHub

Split Char From Str

A small utility to split a string into the first or last character (type char) and the rest (type &str)

Usage

Function call

use split_char_from_str::split_first_char;
let (first_char, rest) = split_first_char("abc").unwrap();
assert_eq!(first_char, 'a');
assert_eq!(rest, "bc");
use split_char_from_str::split_last_char;
let (rest, last_char) = split_last_char("abc").unwrap();
assert_eq!(rest, "ab");
assert_eq!(last_char, 'c');

Method call

use split_char_from_str::SplitCharFromStr;
let (first_char, rest) = "abc".split_first_char().unwrap();
assert_eq!(first_char, 'a');
assert_eq!(rest, "bc");
use split_char_from_str::SplitCharFromStr;
let (rest, last_char) = "abc".split_last_char().unwrap();
assert_eq!(rest, "ab");
assert_eq!(last_char, 'c');

Alternative

If you don't need the first character to be a char, just use str.split_at(1), it will return a tuple of 2 strings.

License

MIT © Hoàng Văn Khải.