[][src]Macro v_escape::new_escape

macro_rules! new_escape {
    ($name:ident, $pairs:expr) => { ... };
    ($name:ident, $pairs:expr, $($t:tt)+) => { ... };
}

Generates struct $name with escaping functionality at fmt

It will get as input:

  • $name: Name of escape class.

  • $pairs: Pairs of [character]->[quote] || [character]->[quote] or [character]->[quote].

  • $t: Optional boolean parameters (simd, avx, sse, print).

    • simd: If true (by default), simd optimizations are enabled. When false, no matter value of avx, sse4.2 will be used,
    • avx: If true (by default), avx optimization are enabled. When false, sse2(if ranges=true and simd=true) or scalar(if simd=false) will be used.
    • ranges: If true (by default), ranges optimizations are enabled. When false, sse4.2(if simd=true) or scalar(if simd=false) will be used.
    • print: If true (false by default), prints out generated code to console.

and will:

  1. Import std::fmt::{self, Display, Formatter}

  2. Define basic struct with attribute bytes and Escape derive functionality

  3. Implements for $name constructors new and From<&'a str>

  4. Implements trait Display for $name with escape functionality

  5. Implements function escape(&str) -> $name

Example

#[macro_use]
extern crate v_escape;

new_escape!(MyEscape, "o->bar");

assert_eq!(escape("foobar").to_string(), "fbarbarbar");