konst::string

Function str_from

Source
pub const fn str_from(string: &str, start: usize) -> &str
Expand description

A const equivalent of &string[start..].

If string.len() < start, this simply returns an empty string` back.

§Panics

This function panics if start is inside the string but doesn’t fall on a char boundary.

§Example

use konst::string::str_from;

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

const SUB0: &str = str_from(STR, 0);
assert_eq!(SUB0, STR);

const SUB1: &str = str_from(STR, 4);
assert_eq!(SUB1, "bar baz");

const SUB2: &str = str_from(STR, 8);
assert_eq!(SUB2, "baz");

const SUB3: &str = str_from(STR, 11);
assert_eq!(SUB3, "");

const SUB4: &str = str_from(STR, 1000);
assert_eq!(SUB3, "");