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");

Return a reference of the inner value.

Convert the type into a String.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Deserialize this value from the given Serde deserializer. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.