Function konst::string::get_up_to

source ·
pub const fn get_up_to(string: &str, len: usize) -> Option<&str>
Expand description

A const equivalent of string.get(..len).

§Example

use konst::string;

const STR: &str = "foo bar baz";

const SUB0: Option<&str> = string::get_up_to(STR, 3);
assert_eq!(SUB0, Some("foo"));

const SUB1: Option<&str> = string::get_up_to(STR, 7);
assert_eq!(SUB1, Some("foo bar"));

const SUB2: Option<&str> = string::get_up_to(STR, 11);
assert_eq!(SUB2, Some(STR));

const SUB3: Option<&str> = string::get_up_to(STR, 100);
assert_eq!(SUB3, None);