Expand description
Pluggable error-message formatters: i18n::MessageFormatter
trait plus i18n::DefaultFormatter (developer-facing,
verbatim) and i18n::UserFormatter (user-facing,
simplified language). Use
crate::Error::render_with_formatter to plug in
localisation tables or custom rendering.
Pluggable error-message formatters for user-facing rendering.
crate::Error’s Display impl is developer-facing — it
preserves the noyalib-internal vocabulary (!!binary, “merge
key”, “recursion depth limit”) that’s useful for debugging but
noisy for end-users of a config-loading binary. The
MessageFormatter trait lets callers plug in their own
formatting strategy: localisation tables, simplification,
richer formatting, or anything else.
Two implementations ship in-tree:
DefaultFormatter— preserves the standard developer-facing message verbatim. Equivalent toformat!("{err}").UserFormatter— collapses noyalib’s diagnostic vocabulary into short user-friendly sentences (“The configuration file has a syntax error on line 5.”) suitable for surfacing in GUIs and--help-style command output.
Use crate::Error::render_with_formatter to render an error
through a chosen formatter.
§Examples
use noyalib::i18n::{DefaultFormatter, UserFormatter};
use noyalib::{from_str, Value};
let err = from_str::<Value>("a: [unclosed").unwrap_err();
let dev = err.render_with_formatter(&DefaultFormatter);
let user = err.render_with_formatter(&UserFormatter);
assert!(!dev.is_empty());
assert!(!user.is_empty());Structs§
- Default
Formatter - Default formatter — preserves the standard developer-facing message verbatim.
- User
Formatter - User-facing formatter — collapses noyalib’s diagnostic
vocabulary into short, plain-language sentences appropriate
for non-developer audiences (CLI
--helptext, GUI alert dialogs).
Traits§
- Message
Formatter - Pluggable formatter for converting an
Errorinto a user-visible message.