pub struct Rule {
pub condition: Condition,
pub samples: Option<Samples>,
}
Expand description
A complete AST representation of a plural rule.
Comprises a vector of AndConditions
and optionally a set of Samples
.
🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways,
including in SemVer minor releases. In particular, the `DataProvider` implementations are only
guaranteed to match with this version's `*_unstable` providers. Use with caution.
§Examples
use icu::plurals::provider::rules::reference::ast::*;
use icu::plurals::provider::rules::reference::{parse, parse_condition};
let condition =
parse_condition(b"i = 5 or v = 2").expect("Parsing failed.");
let samples = Samples {
integer: Some(SampleList {
sample_ranges: vec![SampleRange {
lower_val: DecimalValue("2".to_string()),
upper_val: None,
}],
ellipsis: true,
}),
decimal: Some(SampleList {
sample_ranges: vec![SampleRange {
lower_val: DecimalValue("2.5".to_string()),
upper_val: None,
}],
ellipsis: false,
}),
};
let rule = Rule {
condition,
samples: Some(samples),
};
assert_eq!(
rule,
parse("i = 5 or v = 2 @integer 2, … @decimal 2.5".as_bytes())
.expect("Parsing failed")
)
Fields§
§condition: Condition
The set of conditions that each must be satisfied for the entire Rule
to be satisfied
samples: Option<Samples>
The set of sample numerical values matching each plural category that has a rule, or None
if not present.
Trait Implementations§
impl StructuralPartialEq for Rule
Auto Trait Implementations§
impl Freeze for Rule
impl RefUnwindSafe for Rule
impl Send for Rule
impl Sync for Rule
impl Unpin for Rule
impl UnwindSafe for Rule
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§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more