#str #closures #check #literals #character #generate #macro

macro in_str

A procedural macro to generate a closure that checks if a character is in the provided literal string

1 unstable release

0.1.0 Nov 20, 2024

#585 in Procedural macros

Download history 138/week @ 2024-11-18 8/week @ 2024-11-25 2/week @ 2024-12-02 13/week @ 2024-12-09

161 downloads per month
Used in whitehole

MIT license

4KB

in_str!

Crates.io Version license

use in_str::in_str;

let _ = in_str!("abc");
// equals to
let _ = |c: char| matches!(c, 'a' | 'b' | 'c');
// usually faster than
let _ = |c: char| "abc".contains(c);

// escape will be handled automatically
let _ = in_str!("\n\u{10ffff}");
// equals to
let _ = |c: char| matches!(c, '\n' | '\u{10ffff}');

Dependencies

~1.5MB
~37K SLoC