icu::datetime::provider

Struct PackedPatterns

Source
pub struct PackedPatterns<'data> {
    pub header: u32,
    pub elements: VarZeroVec<'data, PluralElementsPackedULE<ZeroSlice<PatternItem>>>,
}
Expand description

๐Ÿ“ This item has a stack size of 32 bytes on the stable toolchain at release date.

ยงVariants

This supports a set of โ€œstandardโ€ patterns plus up to two โ€œvariantsโ€. The variants are currently used by year formatting:

  • Standard: Year, which could be partial precision (2-digit Gregorian)
  • Variant 0: Full Year, which is always full precision
  • Variant 1: Year With Era

And by time formatting:

  • Standard: Hour only
  • Variant 0: Hour and minute
  • Variant 1: Hour, minute, and second

Variants should be used when the pattern could depend on the value being formatted. For example, with YearStyle::Auto, any of these three patterns could be selected based on the year value.

ยงRepresentation

Currently, there are at most 9 patterns that need to be stored together, named according to this table:

StandardVariant 0Variant 1
LongLaLbLc
MediumMaMbMc
ShortSaSbSc

The header byte encodes which pattern in the patterns array corresponds to a particular cell in the table. It contains the following information:

  • Bits 0-1: โ€œLMSโ€ value of the standard column
  • Bit 2: โ€œQโ€ value: 1 for directly-indexed variants; 0 for per-cell offsets
  • Bits 3-20: Packed offset into patterns table for each variant cell
  • Bits 21-31: unused/reserved

The LMS value determines which pattern index is used for the first column:

LMS ValueLong IndexMedium IndexShort Index
0 (L=M=S)000
1 (L, M=S)011
2 (L=M, S)001
3 (L, M, S)012

If bit 2 is 1 (Q=1), it means there is one pattern per table cell, with the index offset by the short index S from the table above. However, this requires storing multiple, possibly duplicate, patterns in the packed structure. The more common case is Q=0 and then to store per-cell offsets in chunks of 3 bits per cell:

  • Chunk = 0: Inherit according to the table below
  • Chunk = 1-7: Use pattern index Chunk - 1

This is summarized below:

Cell in TableQ=1 Pattern IndexQ=0 Header BitsInheritance
LbS + 13-5La
MbS + 26-8Ma
SbS + 39-11Sa
LcS + 412-14La
McS + 515-17Ma
ScS + 618-20Sa

As a result, if there are no variants, bits 2 and higher will be all zero, making the header int suitable for varint packing, such as that used by postcard and other size-optimized serialization formats.

Fieldsยง

ยงheader: u32

An encoding of which standard/variant cell corresponds to which entry in the patterns table. See class docs.

ยงelements: VarZeroVec<'data, PluralElementsPackedULE<ZeroSlice<PatternItem>>>

The list of patterns. Length should be between 1 and 9, depending on the header.

Implementationsยง

Sourceยง

impl PackedPatterns<'_>

Source

pub fn to_builder(&self) -> PackedPatternsBuilder<'_>

Converts this packed data to a builder that can be mutated.

Trait Implementationsยง

Sourceยง

impl<'data> Bake for PackedPatterns<'data>

Sourceยง

fn bake(&self, env: &CrateEnv) -> TokenStream

Returns a TokenStream that would evaluate to self. Read more
Sourceยง

impl<'data> BakeSize for PackedPatterns<'data>

Sourceยง

fn borrows_size(&self) -> usize

Returns the size
Sourceยง

impl<'data> Clone for PackedPatterns<'data>

Sourceยง

fn clone(&self) -> PackedPatterns<'data>

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<'data> Debug for PackedPatterns<'data>

Sourceยง

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

Formats the value using the given formatter. Read more
Sourceยง

impl<'de, 'data> Deserialize<'de> for PackedPatterns<'data>
where 'de: 'data,

Sourceยง

fn deserialize<D>( deserializer: D, ) -> Result<PackedPatterns<'data>, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Sourceยง

impl MaybeAsVarULE for PackedPatterns<'_>

Sourceยง

type EncodedStruct = [()]

The VarULE type for this data struct, or [()] if it cannot be represented as VarULE.
Sourceยง

impl MaybeEncodeAsVarULE for PackedPatterns<'_>

Sourceยง

fn maybe_encode_as_varule( &self, ) -> Option<&<PackedPatterns<'_> as MaybeAsVarULE>::EncodedStruct>

Returns the MaybeAsVarULE::EncodedStruct that represents this data struct, or None if the data struct does not support this representation.
Sourceยง

impl<'data> PartialEq for PackedPatterns<'data>

Sourceยง

fn eq(&self, other: &PackedPatterns<'data>) -> 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 Serialize for PackedPatterns<'_>

Sourceยง

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Sourceยง

impl<'a> Yokeable<'a> for PackedPatterns<'static>

Sourceยง

type Output = PackedPatterns<'a>

This type MUST be Self with the 'static replaced with 'a, i.e. Self<'a>
Sourceยง

fn transform(&'a self) -> &'a <PackedPatterns<'static> as Yokeable<'a>>::Output

This method must cast self between &'a Self<'static> and &'a Self<'a>. Read more
Sourceยง

fn transform_owned(self) -> <PackedPatterns<'static> as Yokeable<'a>>::Output

This method must cast self between Self<'static> and Self<'a>. Read more
Sourceยง

unsafe fn make( this: <PackedPatterns<'static> as Yokeable<'a>>::Output, ) -> PackedPatterns<'static>

This method can be used to cast away Self<'a>โ€™s lifetime. Read more
Sourceยง

fn transform_mut<F>(&'a mut self, f: F)
where F: 'static + for<'b> FnOnce(&'b mut <PackedPatterns<'static> as Yokeable<'a>>::Output),

This method must cast self between &'a mut Self<'static> and &'a mut Self<'a>, and pass it to f. Read more
Sourceยง

impl<'zf, 'zf_inner> ZeroFrom<'zf, PackedPatterns<'zf_inner>> for PackedPatterns<'zf>

Sourceยง

fn zero_from(this: &'zf PackedPatterns<'zf_inner>) -> PackedPatterns<'zf>

Clone the other C into a struct that may retain references into C.
Sourceยง

impl<'data> Eq for PackedPatterns<'data>

Sourceยง

impl<'data> StructuralPartialEq for PackedPatterns<'data>

Auto Trait Implementationsยง

ยง

impl<'data> Freeze for PackedPatterns<'data>

ยง

impl<'data> RefUnwindSafe for PackedPatterns<'data>

ยง

impl<'data> Send for PackedPatterns<'data>

ยง

impl<'data> Sync for PackedPatterns<'data>

ยง

impl<'data> Unpin for PackedPatterns<'data>

ยง

impl<'data> UnwindSafe for PackedPatterns<'data>

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> IntoEither for T

Sourceยง

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 more
Sourceยง

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Sourceยง

impl<T> Serialize for T
where T: Serialize + ?Sized,

Sourceยง

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Sourceยง

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

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.
Sourceยง

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Sourceยง

impl<T> ErasedDestructor for T
where T: 'static,