Skip to main content

Catalog

Struct Catalog 

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

Implementations§

Source§

impl Catalog

Source

pub fn load(path: &str) -> Result<Self, EngineError>

Strict loader: fails if the file is missing or invalid. Use this at startup when you want the application to refuse to run without a valid catalog (propagate with ? via anyhow in main).

Source

pub fn load_or_fallback(path: &str) -> Self

Infallible loader. If the catalog can’t be read or parsed, returns a Catalog with no entries, remembering the error so render() can surface it as UNK-000 instead of panicking. This is the loader most applications should use.

Source

pub fn from_str(toml: &str) -> Result<Self, EngineError>

Parse a catalog from an in-memory TOML string. Use this to embed a catalog into a library at compile time via include_str!, so it travels with the compiled crate instead of depending on a runtime file path:

pub fn catalog() -> error_engine::Catalog {
    error_engine::Catalog::from_str(include_str!("../errors.toml"))
        .expect("this crate's own catalog is valid TOML")
}
Source

pub fn merged_with(self, other: Catalog) -> Self

Combine two catalogs. Entries in self take priority over entries in other on code collisions — so an app’s own catalog can override a library’s wording, while codes it doesn’t define fall through to the library’s defaults instead of UNK-000.

A load_error on self is preserved as-is: a broken app catalog still renders UNK-000 for everything, but merging never poisons other — each layer degrades independently.

Source

pub fn render(&self, code: &str, ctx: &[(&str, String)]) -> String

Never fails. Falls back to UNK-000 in two cases:

  • the catalog itself failed to load (load_error is set)
  • the code has no entry in an otherwise valid catalog
Source

pub fn hint(&self, code: &str) -> Option<&str>

None in both UNK-000 cases (catalog load failure or missing code).

Trait Implementations§

Source§

impl Debug for Catalog

Source§

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

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

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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 = 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> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more