use std::str::FromStr; use codes_agency::{Agency, Standard, standardized_type}; use codes_common::{code_impl, error, fixed_length_code}; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; // ------------------------------------------------------------------------------------------------ // Public Types // ------------------------------------------------------------------------------------------------ /// /// An instance of the `Standard` struct defined in the /// [`codes_agency`](https://docs.rs/codes-agency/latest/codes_agency/) /// package that describes the ISO-10383 specification. /// pub const ISO_15924: Standard = Standard::new_with_long_ref( Agency::ISO, "15924", "ISO 15924:2022", "Information and documentation — Codes for the representation of names of scripts", "https://www.iso.org/standard/", ); /// /// This enumeration is the set of Scripts defined in ISO 15924. /// #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] pub enum {{ type_name }} {{ "{" }}{% for id in all_ids %} /// {{ codes[id].name }} {{ id }},{% endfor %} {{ "}" }} /// Provides an array of all defined [{{ type_name }}] codes, useful for queries. pub const ALL_CODES: [{{ type_name }};{{ all_ids | length }}] = [{% for id in all_ids %} {{ type_name }}::{{ id }},{% endfor %} ]; pub use codes_common::CodeParseError as {{ type_name }}Error; // ------------------------------------------------------------------------------------------------ // Implementations // ------------------------------------------------------------------------------------------------ impl FromStr for {{ type_name }} {{ "{" }} type Err = {{ type_name }}Error; fn from_str(s: &str) -> Result {{ "{" }} match s {{ "{" }}{% for id in all_ids %} "{{ id }}" => Ok(Self::{{ id }}),{% endfor %} _ => Err(error::unknown_value("{{ type_name }}", s)), {{ "}" }} {{ "}" }} {{ "}" }} code_impl!({{ type_name }}); fixed_length_code!({{ type_name }}, 4); standardized_type!({{ type_name }}, ISO_15924); impl {{ type_name }} {{ "{" }} /// /// Returns the four-letter code for this script. /// pub const fn code(&self) -> &'static str {{ "{" }} match self {{ "{" }}{% for id in all_ids %} Self::{{ id }} => "{{ id }}",{% endfor %} {{ "}" }} {{ "}" }} /// /// Returns the numeric code for this script. /// pub const fn numeric_code(&self) -> u16 {{ "{" }} match self {{ "{" }}{% for id in all_ids %} Self::{{ id }} => {{ codes[id].numeric_code }},{% endfor %} {{ "}" }} {{ "}" }} /// /// Returns the name of this script. /// pub const fn name(&self) -> &'static str {{ "{" }} match self {{ "{" }}{% for id in all_ids %} Self::{{ id }} => "{{ codes[id].name }}",{% endfor %} {{ "}" }} {{ "}" }} /// /// Returns the PVA for this script. /// pub const fn property_value_alias(&self) -> Option<&'static str> {{ "{" }} match self {{ "{" }}{% for id in all_ids %}{% if codes[id].alias %} Self::{{ id }} => Some("{{ codes[id].alias }}"),{% endif %}{% endfor %} _ => None, {{ "}" }} {{ "}" }} /// /// Returns the Unicode version this script was first published. /// pub const fn unicode_version(&self) -> &'static str {{ "{" }} match self {{ "{" }}{% for id in all_ids %} Self::{{ id }} => "{{ codes[id].unicode_version }}",{% endfor %} {{ "}" }} {{ "}" }} /// /// Returns the date this code was added to Unicode as a `YYYY-MM-DD` string for this script. /// pub const fn date_string(&self) -> &'static str {{ "{" }} match self {{ "{" }}{% for id in all_ids %} Self::{{ id }} => "{{ codes[id].date }}",{% endfor %} {{ "}" }} {{ "}" }} {{ "}" }}