Skip to main content

Crate v_escape_base

Crate v_escape_base 

Source
Expand description

A crate for escaping strings

§Features

  • std: Enable standard library features
  • alloc: Enable alloc crate features
  • string: Enable escape_string function
  • fmt: Enable escape_fmt function

§Examples

use v_escape_base::{escape_builder, Escapes, EscapesBuilder, Vector};

#[derive(Debug, Clone, Copy)]
struct Equal<V: Vector> {
    a: V,
}

struct Builder;
impl EscapesBuilder for Builder {
    type Escapes<V: Vector> = Equal<V>;

    fn new<V: Vector>() -> Self::Escapes<V> {
        Equal { a: V::splat(b'a') }
    }
}

impl<V: Vector> Escapes for Equal<V> {
    const ESCAPE_LEN: usize = 1;

    const FALSE_POSITIVE: bool = false;

    type Vector = V;

    #[inline(always)]
    fn masking(&self, vector2: V) -> V {
        self.a.cmpeq(vector2)
    }

    #[inline(always)]
    fn escape(_: usize) -> &'static str {
        "foo"
    }

    #[inline(always)]
    fn position(_: u8) -> usize {
        0
    }

    #[inline(always)]
    fn byte_byte_compare(c: u8) -> bool {
        c == b'a'
    }
}

escape_builder!(Builder);

let mut buffer = String::new();
let haystack = "a".repeat(64);
escape_string(&haystack, &mut buffer);
assert_eq!(buffer, "foo".repeat(64));

let haystack = "a".repeat(64);
assert_eq!(escape_fmt(&haystack).to_string(), "foo".repeat(64));

Modules§

arch
A module for architecture-specific escape functions

Macros§

escape_builder
A macro for creating a escape functions

Traits§

Escapes
A trait that abstracts masking functions for escape sequences.
EscapesBuilder
A builder trait for creating instances of types that implement the Escapes trait.
Vector
A trait for describing vector operations used by vectorized searchers.