in_str 0.1.1

A procedural macro to generate a closure that checks if a character is in the provided literal string.
Documentation
  • Coverage
  • 100%
    2 out of 2 items documented2 out of 2 items with examples
  • Size
  • Source code size: 9.6 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 277.54 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 5s Average build duration of successful builds.
  • all releases: 5s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • DiscreteTom/in_str
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • DiscreteTom

in_str!

license Crates.io Version docs.rs

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

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}');

// also works with byte strings
let _ = in_str!(b"abc");
// equals to
let _ = |c: u8| matches!(c, b'a' | b'b' | b'c');
// escape will be handled automatically
let _ = in_str!(b"\n\xff");
// equals to
let _ = |c: u8| matches!(c, b'\n' | 0xff);