pub trait Localizer {
Show 20 methods
// Provided methods
fn attach_location<'a>(
&self,
base: Cow<'a, str>,
loc: Location,
) -> Cow<'a, str> { ... }
fn root_path_label(&self) -> Cow<'static, str> { ... }
fn alias_defined_at(&self, defined: Location) -> String { ... }
fn alias_used_at(&self, used: Location) -> String { ... }
fn validation_issue_line(
&self,
resolved_path: &str,
entry: &str,
loc: Option<Location>,
) -> String { ... }
fn join_validation_issues(&self, lines: &[String]) -> String { ... }
fn validation_failed(&self, issue_count: usize) -> Cow<'static, str> { ... }
fn validation_failed_documents(&self, document_count: usize) -> String { ... }
fn defined(&self) -> Cow<'static, str> { ... }
fn defined_here(&self) -> Cow<'static, str> { ... }
fn value_used_here(&self) -> Cow<'static, str> { ... }
fn defined_window(&self) -> Cow<'static, str> { ... }
fn anchor_defined_here(&self) -> Cow<'static, str> { ... }
fn included_from_here(&self) -> Cow<'static, str> { ... }
fn error_here(&self) -> Cow<'static, str> { ... }
fn validation_base_message(
&self,
entry: &str,
resolved_path: &str,
) -> String { ... }
fn invalid_here(&self, base: &str) -> String { ... }
fn value_comes_from_the_anchor(&self, def: Location) -> String { ... }
fn snippet_location_prefix(&self, loc: Location) -> String { ... }
fn override_external_message<'a>(
&self,
_msg: ExternalMessage<'a>,
) -> Option<Cow<'a, str>> { ... }
}Expand description
All crate-authored wording customization points.
Implementors should typically override only a few methods. Everything else should default to English (via the default method bodies).
Error::render and the other rendering entrypoints neutralize
control characters in returned message and label text. Calling these low-level hooks
directly bypasses that boundary; sanitize their output (for example with
str::escape_debug) before writing it to a terminal or log.
Provided Methods§
Sourcefn attach_location<'a>(&self, base: Cow<'a, str>, loc: Location) -> Cow<'a, str>
fn attach_location<'a>(&self, base: Cow<'a, str>, loc: Location) -> Cow<'a, str>
Attach an ordinary error-location suffix to base.
Renderers must use this instead of hard-coding English wording like
" at line X, column Y".
Plain alias use and definition locations have separate hooks:
Localizer::alias_used_at and Localizer::alias_defined_at.
Default:
- If
loc == Location::UNKNOWN: returnsbaseunchanged. - Otherwise: returns
"{base} at line {line}, column {column}".
Sourcefn root_path_label(&self) -> Cow<'static, str>
fn root_path_label(&self) -> Cow<'static, str>
Label used when a path has no leaf.
Default <root>
Sourcefn alias_defined_at(&self, defined: Location) -> String
fn alias_defined_at(&self, defined: Location) -> String
Suffix for alias-related errors when a distinct defined-location is available.
Default wording matches the crate’s historical English output:
" (defined at line X, column Y)".
Default: format!(" (defined at line {line}, column {column})", ...).
Sourcefn alias_used_at(&self, used: Location) -> String
fn alias_used_at(&self, used: Location) -> String
Suffix identifying where an aliased value is used in a plain-text diagnostic.
Default: " (used at line X, column Y)", or an empty string for an unknown location.
This replaces the generic Localizer::attach_location call for a known alias use.
Override this hook as well when customizing or suppressing alias-use coordinates;
return an empty string to omit the suffix.
Sourcefn validation_issue_line(
&self,
resolved_path: &str,
entry: &str,
loc: Option<Location>,
) -> String
fn validation_issue_line( &self, resolved_path: &str, entry: &str, loc: Option<Location>, ) -> String
Render one validation issue line.
The crate provides resolved_path, entry and the chosen loc.
Default:
- Base text:
"validation error at {resolved_path}: {entry}". - If
locisSomeand notLocation::UNKNOWN, appends a location suffix viaLocalizer::attach_location.
Sourcefn join_validation_issues(&self, lines: &[String]) -> String
fn join_validation_issues(&self, lines: &[String]) -> String
Join multiple validation issues into one message.
Default: joins lines with a single newline ("\n").
Sourcefn validation_failed(&self, issue_count: usize) -> Cow<'static, str>
fn validation_failed(&self, issue_count: usize) -> Cow<'static, str>
Summary for a validation report whose issues are shown as related miette diagnostics.
Default: "validation failed" for one issue, otherwise
"validation failed (multiple errors)".
Sourcefn validation_failed_documents(&self, document_count: usize) -> String
fn validation_failed_documents(&self, document_count: usize) -> String
Summary for validation failures spanning multiple YAML documents.
Default: "validation failed for {document_count} document(s)".
Sourcefn defined(&self) -> Cow<'static, str>
fn defined(&self) -> Cow<'static, str>
Legacy label for a snippet window at the “definition” site.
Retained for compatibility. Built-in validation snippets now use the actual source name in their headers and do not call this hook.
Default: "(defined)".
Sourcefn defined_here(&self) -> Cow<'static, str>
fn defined_here(&self) -> Cow<'static, str>
Legacy label for a snippet window with only a “defined here” location.
Retained for compatibility. Built-in validation snippets now use the actual source name in their headers and do not call this hook.
Default: "(defined here)".
Sourcefn value_used_here(&self) -> Cow<'static, str>
fn value_used_here(&self) -> Cow<'static, str>
Label used for the primary snippet window when an aliased/anchored value is used at a different location than where it was defined, and for use sites in miette.
Default: "the value is used here".
Sourcefn defined_window(&self) -> Cow<'static, str>
fn defined_window(&self) -> Cow<'static, str>
Label used for the secondary snippet window that points at the anchor definition. Also used for validation definitions and definition-only locations in miette.
For the separate anchor-definition label in miette alias diagnostics, also override
Localizer::anchor_defined_here, which defaults to "anchor defined here"
independently of this method.
Default: "defined here".
Sourcefn anchor_defined_here(&self) -> Cow<'static, str>
fn anchor_defined_here(&self) -> Cow<'static, str>
Label for an alias’s anchor definition in miette diagnostics.
Default: "anchor defined here".
Sourcefn included_from_here(&self) -> Cow<'static, str>
fn included_from_here(&self) -> Cow<'static, str>
Message identifying an include site in a diagnostic.
Used by miette related diagnostics and plain snippet headings. The plain snippet renderer adds a trailing colon.
Default: "included from here" (without a trailing colon).
Sourcefn error_here(&self) -> Cow<'static, str>
fn error_here(&self) -> Cow<'static, str>
Label for the failing value when it differs from the alias definition and use.
Default: "the error occurred here".
Sourcefn validation_base_message(&self, entry: &str, resolved_path: &str) -> String
fn validation_base_message(&self, entry: &str, resolved_path: &str) -> String
Compose the base validation message used in snippets and miette diagnostics.
Default: "validation error: {entry} for {resolved_path}".
Sourcefn invalid_here(&self, base: &str) -> String
fn invalid_here(&self, base: &str) -> String
Compose the “invalid here” prefix for the primary snippet message.
Default: "invalid here, {base}".
Sourcefn value_comes_from_the_anchor(&self, def: Location) -> String
fn value_comes_from_the_anchor(&self, def: Location) -> String
Intro line printed between the primary and secondary snippet windows for anchor/alias (“indirect value”) cases.
Default:
" | This value comes indirectly from the anchor at line {line} column {column}:".
Sourcefn snippet_location_prefix(&self, loc: Location) -> String
fn snippet_location_prefix(&self, loc: Location) -> String
Optional hook to override the location prefix used for snippet titles
Default:
- If
loc == Location::UNKNOWN: returns an empty string. - Otherwise: returns
"line {line} column {column}".
Sourcefn override_external_message<'a>(
&self,
_msg: ExternalMessage<'a>,
) -> Option<Cow<'a, str>>
fn override_external_message<'a>( &self, _msg: ExternalMessage<'a>, ) -> Option<Cow<'a, str>>
Best-effort hook to override/translate dependency-provided message text.
Default: returns None (keep the external message as-is).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".