Struct rosetta_i18n::LanguageId [−][src]
pub struct LanguageId<'a>(_);
Expand description
ISO 639-1 language identifier.
This type holds a string representing a language in the ISO 693-1 format (two-letter code).
The inner value is stored in a Cow
to avoid allocation when possible.
Validation
The type inner value is not validated unless the validate
method is used to initialize the instance.
Generally, you should use this method to initialize this type.
The performed validation only checks that the provided looks like an ISO 693-1language identifier (2 character alphanumeric ascii string).
Serde support
This type implements the Serialize
and Deserialize
traits if the serde
feature is enabled.
Deserialization will fail if the value is not an ISO 639-1 language identifier.
Example
use rosetta_i18n::LanguageId;
let language_id = LanguageId::new("fr");
assert_eq!(language_id.value(), "fr");
let language_id = LanguageId::validate("fr");
assert!(language_id.is_some());
Implementations
Initialize a new valid LanguageId
.
Unlike new
, this method ensures that the provided
value is a valid ISO 693-1 encoded language id.
assert!(LanguageId::validate("fr").is_some());
assert!(LanguageId::validate("invalid").is_none());
Initialize a new LanguageId
from a string.
The provided value must be an ISO 693-1 encoded language id.
If you want to validate the value, use validate
instead.
let language_id = LanguageId::new("en");
assert_eq!(language_id.value(), "en");
Convert the type into a String
.
Trait Implementations
Deserialize this value from the given Serde deserializer. Read more
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
This method tests for !=
.
Auto Trait Implementations
impl<'a> RefUnwindSafe for LanguageId<'a>
impl<'a> Send for LanguageId<'a>
impl<'a> Sync for LanguageId<'a>
impl<'a> Unpin for LanguageId<'a>
impl<'a> UnwindSafe for LanguageId<'a>
Blanket Implementations
Mutably borrows from an owned value. Read more