pub struct Catalog { /* private fields */ }Implementations§
Source§impl Catalog
impl Catalog
Sourcepub fn load(path: &str) -> Result<Self, EngineError>
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).
Sourcepub fn load_or_fallback(path: &str) -> Self
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.
Sourcepub fn from_str(toml: &str) -> Result<Self, EngineError>
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")
}Sourcepub fn merged_with(self, other: Catalog) -> Self
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.