[][src]Struct sanitize_html::rules::pattern::Pattern

pub struct Pattern(pub Box<dyn Fn(&str) -> bool + Sync>);

Value pattern

Methods

impl Pattern[src]

pub fn any() -> Self[src]

Creates pattern which accepts any value.

Example

use sanitize_html::rules::pattern::Pattern;
use regex::Regex;

let pattern = Pattern::any();
assert!(pattern.matches(""));
assert!(pattern.matches("pants"));

pub fn regex(re: Regex) -> Self[src]

Creates pattern which uses regular expression to check a value. Panics

Example

use sanitize_html::rules::pattern::Pattern;
use regex::Regex;

let pattern = Pattern::regex(Regex::new("ant").unwrap());
assert!(!pattern.matches(""));
assert!(pattern.matches("pants"));

pub fn matches(&self, value: &str) -> bool[src]

Checks if a value matches to a pattern.

Trait Implementations

impl Not for Pattern[src]

type Output = Pattern

The resulting type after applying the ! operator.

fn not(self) -> Self::Output[src]

Negates pattern

Example

use sanitize_html::rules::pattern::Pattern;
use regex::Regex;

let pattern = !Pattern::any();
assert!(!pattern.matches(""));
assert!(!pattern.matches("pants"));

impl BitAnd<Pattern> for Pattern[src]

type Output = Pattern

The resulting type after applying the & operator.

fn bitand(self, rhs: Pattern) -> Self::Output[src]

Combines two patterns into a pattern which matches a string iff both patterns match that string.

Example

use sanitize_html::rules::pattern::Pattern;
use regex::Regex;

let pan = Pattern::regex(Regex::new("pan").unwrap());
let ant = Pattern::regex(Regex::new("ant").unwrap());
let pattern = pan & ant;
 
assert!(!pattern.matches("pan"));
assert!(!pattern.matches("ant"));
assert!(pattern.matches("pants"));

impl BitOr<Pattern> for Pattern[src]

type Output = Pattern

The resulting type after applying the | operator.

fn bitor(self, rhs: Pattern) -> Self::Output[src]

Combines two patterns into a pattern which matches a string if one of patterns matches that string.

Example

use sanitize_html::rules::pattern::Pattern;
use regex::Regex;

let pan = Pattern::regex(Regex::new("pan").unwrap());
let pot = Pattern::regex(Regex::new("pot").unwrap());
let pattern = pan | pot;
 
assert!(pattern.matches("pants"));
assert!(pattern.matches("pot"));
assert!(!pattern.matches("jar"));

Auto Trait Implementations

impl !Send for Pattern

impl Sync for Pattern

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]