pub struct ARulebook<A = ()> {
pub rules: AFnRules,
pub owned_values: A,
}Expand description
A set of rules that govern how LocaleFallbackSolver should handle fallbacks.
This is the thread-safe version of Rulebook.
ARulebook<A>, regardless of type A, stores the rules as AFnRules, a vector of boxed
dyn Fn(&LanguageIdentifier) -> Vec<LanguageIdentifier> + Send + Sync. Therefore, the actual
correct name of this struct should be something along the lines of AFnsRulebook.
Obviously this rulebook can be used with the solver because it implements PolyL10nRulebook.
In addition, the default rulebook ARulebook::default() can and probably should be used for
most situations you ever need to deal with.
Fields§
§rules: AFnRules§owned_values: AImplementations§
Source§impl ARulebook<Arc<Vec<ARulebook>>>
impl ARulebook<Arc<Vec<ARulebook>>>
Sourcepub fn from_rulebooks<I: Iterator<Item = ARulebook>>(rulebooks: I) -> Self
pub fn from_rulebooks<I: Iterator<Item = ARulebook>>(rulebooks: I) -> Self
Combine multiple rulebooks into one.
See also: Self::from_ref_rulebooks.
§Examples
let rb1 = poly_l10n::ARulebook::from_fn(|l| {
let mut l = l.clone();
l.script = None;
vec![l]
});
let rb2 = poly_l10n::ARulebook::from_fn(|l| {
let mut l = l.clone();
l.region = None;
vec![l]
});
let rulebook = poly_l10n::ARulebook::from_rulebooks([rb1, rb2].into_iter());
let solv = poly_l10n::LocaleFallbackSolver { rulebook };
assert_eq!(
solv.solve_locale(poly_l10n::langid!["zh-Hant-HK"]),
poly_l10n::langid!["zh-HK", "zh-Hant", "zh"]
);Source§impl<RR, R> ARulebook<(Arc<Vec<RR>>, PhantomData<R>)>
impl<RR, R> ARulebook<(Arc<Vec<RR>>, PhantomData<R>)>
Sourcepub fn from_ref_rulebooks<I: Iterator<Item = RR>>(rulebooks: I) -> Self
pub fn from_ref_rulebooks<I: Iterator<Item = RR>>(rulebooks: I) -> Self
Combine multiple rulebooks into one. Each given rulebook r must implement
AsRef::as_ref.
For the owned version, see Self::from_rulebooks.
§Examples
let rb1 = poly_l10n::ARulebook::from_fn(|l| {
let mut l = l.clone();
l.script = None;
vec![l]
});
let rb2 = poly_l10n::ARulebook::from_fn(|l| {
let mut l = l.clone();
l.region = None;
vec![l]
});
let (rb1, rb2) = (Arc::new(rb1), Arc::new(rb2));
let rulebook = poly_l10n::ARulebook::from_ref_rulebooks([rb1, rb2].iter().cloned());
let solv = poly_l10n::LocaleFallbackSolver { rulebook };
assert_eq!(
solv.solve_locale(poly_l10n::langid!["zh-Hant-HK"]),
poly_l10n::langid!["zh-HK", "zh-Hant", "zh"]
);Source§impl ARulebook
impl ARulebook
pub fn from_fn<F: Fn(&LanguageIdentifier) -> Vec<LanguageIdentifier> + 'static + Send + Sync>( f: F, ) -> Self
pub const fn from_fns(rules: AFnRules) -> Self
Sourcepub fn from_map<M, LS>(map: M) -> Selfwhere
M: for<'a> Index<&'a LanguageIdentifier, Output = LS> + 'static + Send + Sync,
for<'b> &'b LS: IntoIterator<Item = &'b LanguageIdentifier>,
pub fn from_map<M, LS>(map: M) -> Selfwhere
M: for<'a> Index<&'a LanguageIdentifier, Output = LS> + 'static + Send + Sync,
for<'b> &'b LS: IntoIterator<Item = &'b LanguageIdentifier>,
Convert a map (or anything that impl std::ops::Index<&LanguageIdentifier>) into
a rulebook.
The output of the map must implement IntoIterator<Item = &LanguageIdentifier>.
While any valid arguments to this constructor are guaranteed to satisfy the trait
PolyL10nRulebook, it could be useful to convert them to rulebooks, e.g. to combine
multiple rulebooks using Self::from_rulebooks.
Trait Implementations§
Source§impl<A> PolyL10nRulebook<'_> for ARulebook<A>
impl<A> PolyL10nRulebook<'_> for ARulebook<A>
fn find_fallback_locale( &self, locale: &LanguageIdentifier, ) -> impl Iterator<Item = LanguageIdentifier>
fn find_fallback_locale_ref( &'s self, _: &LanguageIdentifier, ) -> impl Iterator<Item = &'s LanguageIdentifier>
Auto Trait Implementations§
impl<A> Freeze for ARulebook<A>where
A: Freeze,
impl<A = ()> !RefUnwindSafe for ARulebook<A>
impl<A> Send for ARulebook<A>where
A: Send,
impl<A> Sync for ARulebook<A>where
A: Sync,
impl<A> Unpin for ARulebook<A>where
A: Unpin,
impl<A = ()> !UnwindSafe for ARulebook<A>
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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>
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