Skip to content

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

License

Notifications You must be signed in to change notification settings

DiscreteTom/in_str

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Installation

cargo add in_str

Usage

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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages