Skip to main content

MessageResolver

Trait MessageResolver 

Source
pub trait MessageResolver {
    // Required method
    fn resolve(&self, key: &str) -> Option<String>;

    // Provided method
    fn plural_category(&self, n: u64) -> &'static str { ... }
}
Expand description

Trait for resolving validation messages by error code key.

Implementations receive the template keys of IssueCode::message_keys() (most specific first, e.g. "too_small.string" then "too_small") and return a template, or None to try the next key / keep the original message.

Templates can use {param_name} placeholders that will be filled from IssueCode::params().

Required Methods§

Source

fn resolve(&self, key: &str) -> Option<String>

Return a translated template for the given error code key, or None to keep the original message.

Provided Methods§

Source

fn plural_category(&self, n: u64) -> &'static str

Plural category of n ("one", "few", "many", "other") for templates with count variants (see translate_issue). Default: English rule (plural_en).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§