pub struct Context<L = NoLocation> {
pub holidays: ContextHolidays,
pub locale: L,
pub approx_bound_interval_size: Option<TimeDelta>,
}
Expand description
All the context attached to a parsed OpeningHours expression and that can alter its evaluation semantics.
Fields§
§holidays: ContextHolidays
A calendar use for evaluation of public and private holidays.
locale: L
Specify locality of the place attached to the expression: from timezone to coordinates.
approx_bound_interval_size: Option<TimeDelta>
As an approximation, consider that any interval bigger that this size is infinite. This can be enabled if you need better performance and you don’t care if a shop is open in more than a year.
Implementations§
Source§impl<L> Context<L>
impl<L> Context<L>
Sourcepub fn with_holidays(self, holidays: ContextHolidays) -> Self
pub fn with_holidays(self, holidays: ContextHolidays) -> Self
Attach a new holidays component to this context.
Sourcepub fn with_locale<L2: Localize>(self, locale: L2) -> Context<L2>
pub fn with_locale<L2: Localize>(self, locale: L2) -> Context<L2>
Attach a new locale component to this context.
Sourcepub fn approx_bound_interval_size(self, max_size: TimeDelta) -> Self
pub fn approx_bound_interval_size(self, max_size: TimeDelta) -> Self
Enables appromiation of long intervals.
Source§impl Context<TzLocation<Tz>>
impl Context<TzLocation<Tz>>
Sourcepub fn from_coords(coords: Coordinates) -> Self
Available on crate features auto-timezone
and auto-country
only.
pub fn from_coords(coords: Coordinates) -> Self
auto-timezone
and auto-country
only.Create a context with given coordinates and try to infer a timezone and a local holiday calendar.
use opening_hours::Context;
use opening_hours::localization::{Coordinates, Country, TzLocation};
let coords = Coordinates::new(48.8535, 2.34839).unwrap();
assert_eq!(
Context::from_coords(coords),
Context::default()
.with_holidays(Country::FR.holidays())
.with_locale(TzLocation::from_coords(coords)),
);
Trait Implementations§
Source§impl Default for Context<NoLocation>
impl Default for Context<NoLocation>
impl<L: Eq> Eq for Context<L>
impl<L> StructuralPartialEq for Context<L>
Auto Trait Implementations§
impl<L> Freeze for Context<L>where
L: Freeze,
impl<L> RefUnwindSafe for Context<L>where
L: RefUnwindSafe,
impl<L> Send for Context<L>where
L: Send,
impl<L> Sync for Context<L>where
L: Sync,
impl<L> Unpin for Context<L>where
L: Unpin,
impl<L> UnwindSafe for Context<L>where
L: UnwindSafe,
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