#first #character #split #string #rest

no-std split-first-char

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

1 unstable release

0.0.0 Apr 26, 2023

#142 in #split

Download history 1/week @ 2023-12-17 1/week @ 2024-02-18 8/week @ 2024-02-25 3/week @ 2024-03-10 38/week @ 2024-03-24 14/week @ 2024-03-31

55 downloads per month

MIT license

4KB

Split First Char

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

Usage

Function call

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

Method call

use split_first_char::SplitFirstChar;
let (first_char, rest) = "abc".split_first_char().unwrap();
assert_eq!(first_char, 'a');
assert_eq!(rest, "bc");

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.

No runtime deps