Module rosetta_i18n::serde_helpers
source · Available on crate feature
serde
only.Expand description
Helpers to use serialize and deserialize types that implement Language
.
Provided helpers
This module provide the as_language
and as_language_with_fallback
serde helpers.
These helpers can be used to serialize and deserialize any type that implements Language
.
The as_language
helper will produce an error when trying to deserialize an unsupported language,
whereas the as_language_with_fallback
helper will return the fallback value.
Example
use rosetta_i18n::{
GenericLanguage,
serde_helpers::{as_language, as_language_with_fallback}
};
#[derive(Serialize, Deserialize)]
struct Config {
#[serde(with = "as_language")]
pub language: GenericLanguage,
#[serde(with = "as_language_with_fallback")]
pub language_fallback: GenericLanguage,
}