Skip to main content

Catalog

Struct Catalog 

Source
pub struct Catalog { /* private fields */ }
Expand description

A validated .mf2b catalog (F2): the fetched buffer and the offsets new found. Share it as Rc<Catalog> / Arc<Catalog>.

Implementations§

Source§

impl Catalog

Source

pub fn new( bytes: Vec<u8>, expect_manifest: u64, ) -> Result<Catalog, CatalogError>

Takes ownership of a fetched .mf2b buffer and validates its structure once: magic, version (F9), manifest_hash (F6), the section table, INDEX bounds and monotonicity, and the NAMES, FUNCS, FALLBACK, LOCALE (with its plural entries) and IDS tables. Strings are checked when read (F4). Linear in the buffer; allocates nothing; no copy (F2).

Source

pub fn manifest_hash(&self) -> u64

The manifest hash this catalog was compiled against (F6).

Source

pub fn locale(&self) -> &str

The BCP 47 tag (F7).

Source

pub fn dir(&self) -> Dir

The locale’s direction (F7): Ltr or Rtl.

Source

pub fn cldr_version(&self) -> Option<CldrVersion>

The CLDR version of the locale data, if any.

Source

pub fn message_count(&self) -> u32

The number of ids in the manifest (INDEX entries).

Source

pub fn as_bytes(&self) -> &[u8] ⓘ

The raw bytes (for serving, hashing, measuring).

Source

pub fn into_bytes(self) -> Vec<u8> ⓘ

Gives the buffer back (a copy, for a catalog over static bytes).

Source

pub fn nfc_map(&self) -> NfcMap<'_>

The canonical-equivalence map this catalog carries (plan/01 §4.3): how the runtime decides whether a value the program passed in is canonically equivalent to one of this catalog’s variant keys or argument names. An absent section is the empty map.

Source

pub fn names_function(&self, pick: impl Fn(&str) -> bool) -> bool

Whether FUNCS names a function pick chooses, given each identifier as FUNCS has it (ns:name, NFC). A catalog that names none has no message that calls one, so a caller asking Catalog::calls of many messages asks this first (plan/08 §4.3: whether a catalog has date messages at all).

Source

pub fn calls(&self, id: MsgId, pick: impl Fn(&str) -> bool) -> bool

Whether message id calls a function pick chooses — in a declaration, a placeholder, or any variant’s pattern — read from its expression and declaration tags and FUNCS, without formatting it (plan/08 §4.3: whether it is a date message). A simple or absent message calls none. A malformed record counts as a call: the caller that acts on true then acts on it too, which is harmless where acting means formatting it again.

Source

pub fn lookup(&self, id: &str) -> Option<MsgId>

Looks a message id up by name (IDS); None when IDS is stripped or the id is unknown. O(log n).

Trait Implementations§

Source§

impl Debug for Catalog

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.