Struct pica_record::matcher::subfield::CardinalityMatcher
source · pub struct CardinalityMatcher { /* private fields */ }
Expand description
A matcher that checks the number of occurrences of a subfield.
Implementations§
source§impl CardinalityMatcher
impl CardinalityMatcher
sourcepub fn new(matcher: &str) -> Result<Self, ParseMatcherError>
pub fn new(matcher: &str) -> Result<Self, ParseMatcherError>
Creates a new CardinalityMatcher.
§Errors
This function fails if the given expression is not a valid cardinality-matcher.
§Example
use pica_record::matcher::subfield::CardinalityMatcher;
let _matcher = CardinalityMatcher::new("#a > 5")?;
sourcepub fn is_match<'a>(
&self,
subfields: impl IntoIterator<Item = &'a SubfieldRef<'a>>,
_options: &MatcherOptions,
) -> bool
pub fn is_match<'a>( &self, subfields: impl IntoIterator<Item = &'a SubfieldRef<'a>>, _options: &MatcherOptions, ) -> bool
Returns true of number of fields with a code equal to the
matcher’s code is ==
, !=
, >=
, >
, <=
, or <
than the
matcher’s value.
§Example
use pica_record::matcher::subfield::CardinalityMatcher;
use pica_record::matcher::MatcherOptions;
use pica_record::primitives::SubfieldRef;
let options = MatcherOptions::default();
let subfields = vec![
SubfieldRef::new('a', "foo")?,
SubfieldRef::new('a', "bar")?,
SubfieldRef::new('b', "baz")?,
];
let matcher = CardinalityMatcher::new("#a >= 2")?;
assert!(matcher.is_match(&subfields, &options));
let matcher = CardinalityMatcher::new("#b < 2")?;
assert!(matcher.is_match(&subfields, &options));
let matcher = CardinalityMatcher::new("#c == 0")?;
assert!(matcher.is_match(&subfields, &options));
Trait Implementations§
source§impl Clone for CardinalityMatcher
impl Clone for CardinalityMatcher
source§fn clone(&self) -> CardinalityMatcher
fn clone(&self) -> CardinalityMatcher
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for CardinalityMatcher
impl Debug for CardinalityMatcher
source§impl Display for CardinalityMatcher
impl Display for CardinalityMatcher
source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Format the cardinality-matcher as a human-readable string.
§Example
use pica_record::matcher::subfield::CardinalityMatcher;
use pica_record::matcher::MatcherOptions;
let matcher = CardinalityMatcher::new("#a >= 3")?;
assert_eq!(matcher.to_string(), "#a >= 3");
source§impl PartialEq for CardinalityMatcher
impl PartialEq for CardinalityMatcher
impl StructuralPartialEq for CardinalityMatcher
Auto Trait Implementations§
impl Freeze for CardinalityMatcher
impl RefUnwindSafe for CardinalityMatcher
impl Send for CardinalityMatcher
impl Sync for CardinalityMatcher
impl Unpin for CardinalityMatcher
impl UnwindSafe for CardinalityMatcher
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)