Macro obfstr::position

source ·
macro_rules! position {
    ($haystack:expr, $needle:expr) => { ... };
}
Expand description

Finds the position of the needle in the haystack at compiletime.

Produces a const-eval error if the needle is not a substring of the haystack.

Examples

assert_eq!(obfstr::position!("haystack", "st"), 3..5);

Use this API when pooling strings in a single obfstr:

const POOL: &str = concat!("Foo", "Bar", "Baz");

obfstr::obfstr! { let pool = POOL; }

// Later, read strings from the pool
let foo = &pool[obfstr::position!(POOL, "Foo")];
let bar = &pool[obfstr::position!(POOL, "Bar")];
let baz = &pool[obfstr::position!(POOL, "Baz")];