pub enum FilterValue<'a> {
Null,
Bool(bool),
Number(f64),
String(Cow<'a, str>),
Tuple(Vec<FilterValue<'a>>),
}Expand description
A value which may appear within a filter expression, either as a literal
or as the result of resolving a property on a Filterable object.
FilterValue implements From for most primitive Rust types (booleans,
numbers, strings, Options, and vectors of values), making it easy to
construct from your own data within a Filterable::get implementation.
use filt_rs::FilterValue;
let value: FilterValue<'_> = 42.into();
assert_eq!(value, FilterValue::Number(42.0));
let value: FilterValue<'_> = Some("hello").into();
assert_eq!(value, FilterValue::String("hello".into()));
let value: FilterValue<'_> = None::<bool>.into();
assert_eq!(value, FilterValue::Null);Note that string equality comparisons between FilterValues are
case-insensitive, mirroring the behaviour of the filter language itself.
Case is folded character-by-character using the language’s Unicode
case-folding rules (with all Greek sigma forms treated as equivalent),
so multi-character folds such as ß → ss compare equal too.
use filt_rs::FilterValue;
let a: FilterValue<'_> = "Hello".into();
let b: FilterValue<'_> = "hello".into();
assert_eq!(a, b);
let a: FilterValue<'_> = "STRASSE".into();
let b: FilterValue<'_> = "straße".into();
assert_eq!(a, b);Variants§
Null
The absence of a value, also returned for unknown property keys.
Bool(bool)
A boolean value (true or false).
Number(f64)
A numeric value; all numbers are represented as 64-bit floats.
String(Cow<'a, str>)
A string value, compared case-insensitively by the filter language.
The string may borrow from the object being filtered (when produced
by a Filterable::get implementation) or own its data, courtesy of
the Cow.
Tuple(Vec<FilterValue<'a>>)
An ordered list of values, written as [a, b, c] in filter expressions.
Implementations§
Source§impl<'a> FilterValue<'a>
impl<'a> FilterValue<'a>
Sourcepub fn is_truthy(&self) -> bool
pub fn is_truthy(&self) -> bool
Determines whether this value is considered “truthy” by the filter language.
Filters match an object when their expression evaluates to a truthy
value. FilterValue::Null, false, 0, empty strings, and empty
tuples are falsy; everything else is truthy.
With the chrono feature enabled, datetimes are always truthy, while
durations are truthy if (and only if) they are non-zero.
use filt_rs::FilterValue;
assert!(FilterValue::Bool(true).is_truthy());
assert!(FilterValue::String("hello".into()).is_truthy());
assert!(!FilterValue::Null.is_truthy());
assert!(!FilterValue::Number(0.0).is_truthy());Sourcepub fn contains(&self, other: &FilterValue<'a>) -> bool
pub fn contains(&self, other: &FilterValue<'a>) -> bool
Determines whether this value contains the provided value.
For tuples, this checks whether any element is equal to other; for
strings, it performs a case-insensitive substring search. All other
combinations return false. This powers the contains and in
operators in the filter language.
The string comparison case-folds both operands character-by-character
without allocating, using the same Unicode case-folding rules as the
rest of the filter language: all Greek sigma forms (Σ, σ, and the
final-position ς) are treated as equivalent regardless of where they
appear in a word, and multi-character folds such as ß → ss
participate fully.
use filt_rs::FilterValue;
let haystack: FilterValue<'_> ="Hello World".into();
assert!(haystack.contains(&"world".into()));
let tuple = FilterValue::Tuple(vec!["a".into(), "b".into()]);
assert!(tuple.contains(&"a".into()));
assert!(!tuple.contains(&"c".into()));Sourcepub fn startswith(&self, other: &FilterValue<'a>) -> bool
pub fn startswith(&self, other: &FilterValue<'a>) -> bool
Determines whether this value starts with the provided value.
For strings, this performs a case-insensitive prefix test; for tuples,
it checks whether any element is equal to other. This powers the
startswith operator in the filter language.
The string comparison case-folds both operands character-by-character
without allocating, using the same Unicode case-folding rules as the
rest of the filter language (see FilterValue::contains).
use filt_rs::FilterValue;
let value: FilterValue<'_> ="Hello World".into();
assert!(value.startswith(&"hello".into()));
assert!(!value.startswith(&"world".into()));Sourcepub fn endswith(&self, other: &FilterValue<'a>) -> bool
pub fn endswith(&self, other: &FilterValue<'a>) -> bool
Determines whether this value ends with the provided value.
For strings, this performs a case-insensitive suffix test; for tuples,
it checks whether any element is equal to other. This powers the
endswith operator in the filter language.
The string comparison case-folds both operands character-by-character
without allocating, using the same Unicode case-folding rules as the
rest of the filter language (see FilterValue::contains).
use filt_rs::FilterValue;
let value: FilterValue<'_> ="Hello World".into();
assert!(value.endswith(&"WORLD".into()));
assert!(!value.endswith(&"hello".into()));Sourcepub fn eq_cs(&self, other: &FilterValue<'a>) -> bool
pub fn eq_cs(&self, other: &FilterValue<'a>) -> bool
Determines whether this value is equal to the provided value, comparing strings case-sensitively.
This is the case-sensitive counterpart of the == operator (and the
PartialEq implementation): tuples compare their elements with
eq_cs recursively, and all other variants behave exactly as ==
does. It underpins tuple membership for the contains_cs and in_cs
operators in the filter language.
use filt_rs::FilterValue;
let value: FilterValue<'_> ="Hello".into();
assert!(value.eq_cs(&"Hello".into()));
assert!(!value.eq_cs(&"hello".into()));Sourcepub fn contains_cs(&self, other: &FilterValue<'a>) -> bool
pub fn contains_cs(&self, other: &FilterValue<'a>) -> bool
Determines whether this value contains the provided value, comparing strings case-sensitively.
This is the case-sensitive counterpart of FilterValue::contains:
tuples check whether any element is eq_cs to
other, strings perform an exact substring search, and all other
combinations return false. This powers the contains_cs and in_cs
operators in the filter language.
use filt_rs::FilterValue;
let haystack: FilterValue<'_> ="Hello World".into();
assert!(haystack.contains_cs(&"World".into()));
assert!(!haystack.contains_cs(&"world".into()));Sourcepub fn startswith_cs(&self, other: &FilterValue<'a>) -> bool
pub fn startswith_cs(&self, other: &FilterValue<'a>) -> bool
Determines whether this value starts with the provided value, comparing strings case-sensitively.
This is the case-sensitive counterpart of FilterValue::startswith,
powering the startswith_cs operator in the filter language.
use filt_rs::FilterValue;
let value: FilterValue<'_> ="Hello World".into();
assert!(value.startswith_cs(&"Hello".into()));
assert!(!value.startswith_cs(&"hello".into()));Sourcepub fn endswith_cs(&self, other: &FilterValue<'a>) -> bool
pub fn endswith_cs(&self, other: &FilterValue<'a>) -> bool
Determines whether this value ends with the provided value, comparing strings case-sensitively.
This is the case-sensitive counterpart of FilterValue::endswith,
powering the endswith_cs operator in the filter language.
use filt_rs::FilterValue;
let value: FilterValue<'_> ="Hello World".into();
assert!(value.endswith_cs(&"World".into()));
assert!(!value.endswith_cs(&"WORLD".into()));Trait Implementations§
Source§impl<'a> Clone for FilterValue<'a>
impl<'a> Clone for FilterValue<'a>
Source§fn clone(&self) -> FilterValue<'a>
fn clone(&self) -> FilterValue<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'a> Debug for FilterValue<'a>
impl<'a> Debug for FilterValue<'a>
Source§impl<'a> Default for FilterValue<'a>
impl<'a> Default for FilterValue<'a>
Source§fn default() -> FilterValue<'a>
fn default() -> FilterValue<'a>
Source§impl<'a> Display for FilterValue<'a>
impl<'a> Display for FilterValue<'a>
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats the value as it would appear within a filter expression.
use filt_rs::FilterValue;
let value = FilterValue::Tuple(vec!["a".into(), 1.into(), FilterValue::Null]);
assert_eq!(value.to_string(), r#"["a", 1, null]"#);Secret values (available with the secrecy feature) are always
formatted as [REDACTED], never as their underlying string.
Source§impl<'a> From<&'a str> for FilterValue<'a>
impl<'a> From<&'a str> for FilterValue<'a>
Source§fn from(s: &'a str) -> Self
fn from(s: &'a str) -> Self
Borrows the string slice rather than copying it, so a Filterable::get
implementation returning self.field.as_str().into() performs no
allocation. Use From<String> (or .to_string().into()) when you
need the value to own its data instead.