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 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.