use codes_agency::{Agency, Standard, standardized_type}; use codes_common::{code_impl, error, fixed_length_code}; use std::str::FromStr; #[cfg(feature = "location")] use codes_iso_3166::part_1::CountryCode; #[cfg(feature = "legal_entity")] use codes_iso_17442::LegalEntityId; #[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_10383: Standard = Standard::new_with_long_ref( Agency::ISO, "10383", "ISO 10383:2012", "Securities and related financial instruments — Codes for exchanges and market identification (MIC)", "https://www.iso.org/standard/61067.html", ); /// /// /// See more at [iso.org](https://www.iso.org/standard/61067.html). /// #[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].market_name }} {% if id is matching("^[0-9]") %}#[allow(non_camel_case_types)] m{% endif %}{{ 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 }}::{% if id is matching("^[0-9]") %}m{% endif %}{{ 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::{% if id is matching("^[0-9]") %}m{% endif %}{{ id }}),{% endfor %} _ => Err(error::unknown_value("{{ type_name }}", s)), {{ "}" }} {{ "}" }} {{ "}" }} code_impl!({{ type_name }}); fixed_length_code!({{ type_name }}, 4); standardized_type!({{ type_name }}, ISO_10383); impl {{ type_name }} {{ "{" }} /// /// Market Identifier Code allocated to the market named /// in ‘Market Name-Institution Description’ /// pub const fn code(&self) -> &'static str {{ "{" }} match self {{ "{" }}{% for id in all_ids %} Self::{% if id is matching("^[0-9]") %}m{% endif %}{{ id }} => "{{ id }}",{% endfor %} {{ "}" }} {{ "}" }} // -------------------------------------------------------------------------------------------- // Required/Guaranteed // -------------------------------------------------------------------------------------------- /// /// The entity operating an exchange/market/trade reporting /// facility in a specific market/country. /// pub const fn operating_code(&self) -> Option {{ "{" }} match self {{ "{" }}{% for id in all_ids %}{% if codes[id].operating_mic %}{% set op_mic = codes[id].operating_mic %} Self::{% if id is matching("^[0-9]") %}m{% endif %}{{ id }} => Some(Self::{% if op_mic is matching("^[0-9]") %}m{% endif %}{{ op_mic }}),{% endif %}{% endfor %} _ => None, {{ "}" }} {{ "}" }} /// /// Returns `true` if this MIC represents a segment within an operating /// MIC. /// pub const fn is_segment(&self) -> bool { self.operating_code().is_some() } /// /// The name, or institution description, of the market. /// #[cfg(feature = "market_name")] pub const fn market_name(&self) -> &'static str {{ "{" }} match self {{ "{" }}{% for id in all_ids %} Self::{% if id is matching("^[0-9]") %}m{% endif %}{{ id }} => "{{ codes[id].market_name }}",{% endfor %} {{ "}" }} {{ "}" }} /// /// ISO country code (see ISO 3166-1): alpha-2 code of the country where /// the market is /// #[cfg(feature = "location")] pub const fn country_code(&self) -> Option {{ "{" }} match self {{ "{" }}{% for id in all_ids %}{% if codes[id].country_code %} Self::{% if id is matching("^[0-9]") %}m{% endif %}{{ id }} => Some(CountryCode::{{ codes[id].country_code }}),{% endif %}{% endfor %} _ => None, {{ "}" }} {{ "}" }} /// /// City: city where the market is located. /// #[cfg(feature = "location")] pub const fn city(&self) -> &'static str {{ "{" }} match self {{ "{" }}{% for id in all_ids %} Self::{% if id is matching("^[0-9]") %}m{% endif %}{{ id }} => "{{ codes[id].city }}",{% endfor %} {{ "}" }} {{ "}" }} /// /// Status: active, updated (since last publication), expired (= /// deactivated). /// pub const fn status(&self) -> Status {{ "{" }} match self {{ "{" }}{% for id in all_ids %} Self::{% if id is matching("^[0-9]") %}m{% endif %}{{ id }} => Status::{{ codes[id].status | capitalize }},{% endfor %} {{ "}" }} {{ "}" }} /// /// Creation date: date indicating when the MIC was originally created. /// #[cfg(feature = "dates")] pub const fn creation_date(&self) -> &'static str {{ "{" }} match self {{ "{" }}{% for id in all_ids %} Self::{% if id is matching("^[0-9]") %}m{% endif %}{{ id }} => "{{ codes[id].created }}",{% endfor %} {{ "}" }} {{ "}" }} // -------------------------------------------------------------------------------------------- // Optional // -------------------------------------------------------------------------------------------- /// /// The legal name of the entity owning the market. /// #[cfg(feature = "legal_entity")] pub const fn legal_entity_name(&self) -> Option<&'static str> {{ "{" }} match self {{ "{" }}{% for id in all_ids %}{% if codes[id].legal_entity_name %} Self::{% if id is matching("^[0-9]") %}m{% endif %}{{ id }} => Some("{{ codes[id].legal_entity_name }}"),{% endif %}{% endfor %} _ => None, {{ "}" }} {{ "}" }} /// /// The Legal Entity Identifier (LEI) of the entity owning the /// market. See ISO 17442-1. /// #[cfg(feature = "legal_entity")] pub fn legal_entity_id(&self) -> Option {{ "{" }} match self {{ "{" }}{% for id in all_ids %}{% if codes[id].legal_entity_id %} Self::{% if id is matching("^[0-9]") %}m{% endif %}{{ id }} => Some(LegalEntityId::from_str("{{ codes[id].legal_entity_id }}").unwrap()),{% endif %}{% endfor %} _ => None, {{ "}" }} {{ "}" }} /// /// Market category: specifies the type of market. The list of market types /// is predefined (1). The list can be updated upon request to the RA, /// which will validate the request. /// pub const fn market_category_code(&self) -> Option {{ "{" }} match self {{ "{" }}{% for id in all_ids %}{% if codes[id].category_code %} Self::{% if id is matching("^[0-9]") %}m{% endif %}{{ id }} => Some(Category::{{ codes[id].category_code }}),{% endif %}{% endfor %} _ => None, {{ "}" }} {{ "}" }} /// /// Acronym: known acronym of the market. /// pub const fn acronym(&self) -> Option<&'static str> {{ "{" }} match self {{ "{" }}{% for id in all_ids %}{% if codes[id].acronym %} Self::{% if id is matching("^[0-9]") %}m{% endif %}{{ id }} => Some("{{ codes[id].acronym }}"),{% endif %}{% endfor %} _ => None, {{ "}" }} {{ "}" }} pub fn from_str_extended(s: &str) -> Result {{ "{" }} if let Ok(market) = Self::from_str(s) {{ "{" }} Ok(market) {{ "}" }} else {{ "{" }} #[allow(unreachable_patterns)] match s {{ "{" }}{% for id in all_ids %}{% if codes[id].acronym and codes[id].acronym != id and not codes[id].operating_mic %} "{{ codes[id].acronym }}" => Ok(Self::{% if id is matching("^[0-9]") %}m{% endif %}{{ id }}),{% endif %}{% endfor %} _ => Err(error::unknown_value("{{ type_name }}", s)), {{ "}" }} {{ "}" }} {{ "}" }} /// /// Website: website of the market. /// #[cfg(feature = "real_url")] pub fn website_url(&self) -> Option {{ "{" }} match self {{ "{" }}{% for id in all_ids %}{% if codes[id].url %} Self::{% if id is matching("^[0-9]") %}m{% endif %}{{ id }} => Some(url::Url::from_str("http://{{ codes[id].url | lower }}").unwrap()),{% endif %}{% endfor %} _ => None, {{ "}" }} {{ "}" }} /// /// Website: website of the market. /// #[cfg(not(feature = "real_url"))] pub const fn website_url(&self) -> Option<&'static str> {{ "{" }} match self {{ "{" }}{% for id in all_ids %}{% if codes[id].url %} Self::{% if id is matching("^[0-9]") %}m{% endif %}{{ id }} => Some("http://{{ codes[id].url | lower }}"),{% endif %}{% endfor %} _ => None, {{ "}" }} {{ "}" }} /// /// Last update date: date indicating when the MIC was last modified /// #[cfg(feature = "dates")] pub const fn last_update_date(&self) -> &'static str {{ "{" }} match self {{ "{" }}{% for id in all_ids %}{% if codes[id].last_modified %} Self::{% if id is matching("^[0-9]") %}m{% endif %}{{ id }} => "{{ codes[id].last_modified }}",{% endif %}{% endfor %} {{ "}" }} {{ "}" }} /// /// Last validation date: date indicating when the MIC was last reviewed /// for correctness. /// #[cfg(feature = "dates")] pub const fn last_validation_date(&self) -> Option<&'static str> {{ "{" }} match self {{ "{" }}{% for id in all_ids %}{% if codes[id].last_validated %} Self::{% if id is matching("^[0-9]") %}m{% endif %}{{ id }} => Some("{{ codes[id].last_validated }}"),{% endif %}{% endfor %} _ => None, {{ "}" }} {{ "}" }} /// /// Expiry date: The expiry date is populated when the MIC is deactivated; upon /// request from the MIC owner; following market research (user request) or /// maintenance. The expiry date field is left blank when a MIC is created. /// #[cfg(feature = "dates")] pub const fn expiration_date(&self) -> Option<&'static str> {{ "{" }} match self {{ "{" }}{% for id in all_ids %}{% if codes[id].expirey_date %} Self::{% if id is matching("^[0-9]") %}m{% endif %}{{ id }} => Some("{{ codes[id].expirey_date }}"),{% endif %}{% endfor %} _ => None, {{ "}" }} {{ "}" }} /// /// Comments: any additional information worth mentioning to help users with identifying the /// exchange or understanding a modification. /// #[cfg(feature = "comments")] pub const fn comments(&self) -> Option<&'static str> {{ "{" }} match self {{ "{" }}{% for id in all_ids %}{% if codes[id].comments %} Self::{% if id is matching("^[0-9]") %}m{% endif %}{{ id }} => Some("{{ codes[id].comments | replace(from='"', to='\"') }}"),{% endif %}{% endfor %} _ => None, {{ "}" }} {{ "}" }} {{ "}" }}