Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Avhz RustQuant ISO 3166

From Leeroopedia


Knowledge Sources
Domains Financial_Standards, Quantitative_Finance
Last Updated 2026-02-07 19:00 GMT

Overview

Concrete tool for representing ISO 3166 country codes provided by the RustQuant library.

Description

The ISO_3166 struct encapsulates a country representation according to the ISO 3166-1 standard, storing three fields: the alpha-2 code (two-letter, e.g., "US"), the alpha-3 code (three-letter, e.g., "USA"), and the numeric code (e.g., "840"). The struct provides accessor methods for each field (alpha_2(), alpha_3(), numeric()) and a lookup function from_alpha_2() that converts a two-letter country code string into the corresponding ISO_3166 struct via an exhaustive match statement covering all recognized countries from Afghanistan to Zimbabwe. Constants are defined for each country (e.g., UNITED_STATES, GERMANY, AUSTRALIA) so they can be used directly in code.

Usage

Use this module when you need standardized country identification in financial applications, such as mapping exchanges to countries, validating counterparty jurisdictions, or filtering instruments by country of origin.

Code Reference

Source Location

Signature

#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub struct ISO_3166 {
    pub alpha_2: &'static str,
    pub alpha_3: &'static str,
    pub numeric: &'static str,
}

impl ISO_3166 {
    pub fn alpha_2(&self) -> &'static str;
    pub fn alpha_3(&self) -> &'static str;
    pub fn numeric(&self) -> &'static str;
    pub fn from_alpha_2(alpha_2: &str) -> Option<Self>;
}

Import

use RustQuant::iso::ISO_3166;

I/O Contract

Inputs

Name Type Required Description
alpha_2 &'static str Yes ISO 3166-1 alpha-2 country code (e.g., "US")
alpha_3 &'static str Yes ISO 3166-1 alpha-3 country code (e.g., "USA")
numeric &'static str Yes ISO 3166-1 numeric code (e.g., "840")

Outputs

Name Type Description
ISO_3166 struct A country code struct with all three ISO 3166-1 representations
Option<ISO_3166> Option from_alpha_2() returns Some(ISO_3166) if valid code, None otherwise

Usage Examples

use RustQuant::iso::{ISO_3166, UNITED_STATES, GERMANY};

// Use pre-defined country constants
let us = UNITED_STATES;
assert_eq!(us.alpha_2(), "US");
assert_eq!(us.alpha_3(), "USA");
assert_eq!(us.numeric(), "840");

// Look up a country by alpha-2 code
if let Some(country) = ISO_3166::from_alpha_2("DE") {
    assert_eq!(country.alpha_3(), "DEU");
}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment