jiff::tz::timezone::repr

Struct Repr

Source
pub(super) struct Repr {
    ptr: *const u8,
}
Expand description

The internal representation of a TimeZone.

It has 6 different possible variants: UTC, Etc/Unknown, fixed offset, static TZif, Arc TZif or Arc POSIX time zone.

This design uses pointer tagging so that:

  • The size of a TimeZone stays no bigger than a single word.
  • In core-only environments, a TimeZone can be created from compile-time TZif data without allocating.
  • UTC, unknown and fixed offset time zone does not require allocating.
  • We can still alloc for TZif and POSIX time zones created at runtime. (Allocating for TZif at runtime is the intended common case, and corresponds to reading /usr/share/zoneinfo entries.)

We achieve this through pointer tagging and careful use of a strict provenance polyfill (because of MSRV). We use the lower 4 bits of a pointer to indicate which variant we have. This is sound because we require all types that we allocate for to have a minimum alignment of 8 bytes.

Fields§

§ptr: *const u8

Implementations§

Source§

impl Repr

Source

const BITS: usize = 7usize

Source

pub(super) const UTC: usize = 1usize

Source

pub(super) const UNKNOWN: usize = 2usize

Source

pub(super) const FIXED: usize = 3usize

Source

pub(super) const STATIC_TZIF: usize = 0usize

Source

pub(super) const ARC_TZIF: usize = 4usize

Source

pub(super) const ARC_POSIX: usize = 5usize

Source

const ALIGN: usize = 8usize

Source

pub(super) const fn utc() -> Repr

Creates a representation for a UTC time zone.

Source

pub(super) const fn unknown() -> Repr

Creates a representation for a Etc/Unknown time zone.

Source

pub(super) const fn fixed(offset: Offset) -> Repr

Creates a representation for a fixed offset time zone.

Source

pub(super) const fn static_tzif( tzif: &'static Tzif<&'static str, &'static str, &'static [TzifLocalTimeType], &'static [i64], &'static [TzifDateTime], &'static [TzifDateTime], &'static [TzifTransitionInfo]>, ) -> Repr

Creates a representation for a created-at-compile-time TZif time zone.

This can only be correctly called by the jiff-static proc macro.

Source

pub(super) fn arc_tzif( tzif: Arc<Tzif<String, ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>>, ) -> Repr

Creates a representation for a TZif time zone.

Source

pub(super) fn arc_posix( posix_tz: Arc<PosixTimeZone<ArrayStr<ABBREVIATION_MAX>>>, ) -> Repr

Creates a representation for a POSIX time zone.

Source

pub(super) unsafe fn get_fixed(&self) -> Offset

Gets the offset representation.

§Safety

Callers must ensure that the pointer tag is FIXED.

Source

pub(super) fn is_unknown(&self) -> bool

Returns true if and only if this representation corresponds to the Etc/Unknown time zone.

Source

pub(super) unsafe fn get_static_tzif( &self, ) -> &'static Tzif<&'static str, &'static str, &'static [TzifLocalTimeType], &'static [i64], &'static [TzifDateTime], &'static [TzifDateTime], &'static [TzifTransitionInfo]>

Gets the static TZif representation.

§Safety

Callers must ensure that the pointer tag is STATIC_TZIF.

Source

pub(super) unsafe fn get_arc_tzif<'a>( &'a self, ) -> &'a Tzif<String, ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>

Gets the Arc TZif representation.

§Safety

Callers must ensure that the pointer tag is ARC_TZIF.

Source

pub(super) unsafe fn get_arc_posix<'a>( &'a self, ) -> &'a PosixTimeZone<ArrayStr<ABBREVIATION_MAX>>

Gets the Arc POSIX time zone representation.

§Safety

Callers must ensure that the pointer tag is ARC_POSIX.

Source

pub(super) fn tag(&self) -> usize

Returns the tag on the representation’s pointer.

The value is guaranteed to be one of the constant tag values.

Source

pub(super) const unsafe fn copy(&self) -> Repr

Returns a dumb copy of this representation.

§Safety

Callers must ensure that this representation’s tag is UTC, UNKNOWN, FIXED or STATIC_TZIF.

Namely, this specifically does not increment the ref count for the Arc pointers when the tag is ARC_TZIF or ARC_POSIX. This means that incorrect usage of this routine can lead to use-after-free.

NOTE: It would be nice if we could make this copy routine safe, or at least panic if it’s misused. But to do that, you need to know the time zone variant. And to know the time zone variant, you need to “look” at the tag in the pointer. And looking at the address of a pointer in a const context is precarious.

Trait Implementations§

Source§

impl Clone for Repr

Source§

fn clone(&self) -> Repr

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Repr

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Repr

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl PartialEq for Repr

Source§

fn eq(&self, other: &Repr) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Repr

Source§

impl Send for Repr

Source§

impl Sync for Repr

Auto Trait Implementations§

§

impl Freeze for Repr

§

impl RefUnwindSafe for Repr

§

impl Unpin for Repr

§

impl UnwindSafe for Repr

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.