pub trait Rule: Send + Sync {
// Required methods
fn name(&self) -> &'static str;
fn check(&self, input: &str) -> RuleResult;
}Expand description
A sanitization rule that inspects an input string and reports violations.
Implement this trait to create custom rules. Rules are composable via
Sanitizer.
§Example
use shell_sanitize::{Rule, RuleResult, RuleViolation};
struct NoSpacesRule;
impl Rule for NoSpacesRule {
fn name(&self) -> &'static str { "no_spaces" }
fn check(&self, input: &str) -> RuleResult {
let violations: Vec<_> = input
.char_indices()
.filter(|(_, c)| *c == ' ')
.map(|(i, _)| RuleViolation::new(self.name(), "space character found")
.at(i)
.with_fragment(" "))
.collect();
if violations.is_empty() { Ok(()) } else { Err(violations) }
}
}Required Methods§
Sourcefn check(&self, input: &str) -> RuleResult
fn check(&self, input: &str) -> RuleResult
Check the input and return violations, if any.