Skip to main content

Crate diurn_mic

Crate diurn_mic 

Source
Expand description

Parser, model, registry, and diff for the ISO 10383 Market Identifier Code registry.

§Scope

This crate reads the ISO 10383 CSV and gives you typed records. It does not fetch, render, or know anything about market calendars. There is no async runtime, no HTTP client, and no CLI framework in its dependency tree.

It also owns the on-disk convention for registry files — what a vintage is named (filename_for, classify_filename) and where vintages live (data_dir). That is here rather than in each tool because two answers to “where is it” means one of them is eventually wrong on somebody’s machine, and the failure is a command that cannot find a file another command just wrote. None of it walks a directory or opens anything.

§Loading never fails on one bad row

ISO will eventually ship a malformed record. That must degrade, not fail, so MicRegistry::load_csv returns both the registry and a Vec<Issue> describing everything questionable it found:

use diurn_mic::{LoadOptions, MicRegistry, Severity};
use jiff::civil::date;

let file = std::fs::File::open("ISO10383_MIC_2026-08-10.csv")?;
let outcome = MicRegistry::load_csv(file, LoadOptions::new(date(2026, 8, 10)))?;

let fatal = outcome.issues.iter().filter(|i| i.severity == Severity::Error);
println!("{} records, {} unusable", outcome.registry.len(), fatal.count());

Only Severity::Error causes a row to be dropped, and that is reserved for records that cannot be keyed at all.

§Pending records

ISO publishes on the second Monday of each month; the changes in that file take effect on the fourth Monday. A freshly published registry therefore contains records that are not yet in force, marked Status::Updated and carrying a last_updated in the future.

This is normal, not an error. Use MicRegistry::as_of to get the registry as it stands on a given date rather than serving pending state as current.

§The publication date

It is not a column in the CSV, and the ISO download URL is unversioned, so nothing about a file on disk announces which vintage it is. Supply it:

MicRegistry::load_csv(file, LoadOptions::new(date(2026, 8, 10)))?;

It matters because IssueKind::FutureDatedRecord, MicRegistry::is_pending, and MicRegistry::as_of all key off it.

§Recovering it from the file

When you do not have the date — a download that arrived without one — it can usually be recovered, because the publication cycle above leaves a fingerprint in the data. The fourth Monday is a fortnight after the second, so the latest last_updated in a file with pending records implies the publication date exactly:

let outcome = MicRegistry::load_csv(file, LoadOptions::infer())?;
assert_eq!(
    outcome.registry.published_source(),
    PublishedSource::InferredFromEffectiveDate
);

Prefer a known date when you have one. Inference is best-effort and clock-free, so it cannot distinguish a current effective date from a stale one left over from an earlier cycle — see publication_date_from_effective for the limits, and check MicRegistry::published_source to see which rule applied.

Structs§

CountryCode
An ISO 3166-1 alpha-2 country code.
DataDir
Where fetched registries live, and any reason the obvious answer was not used.
FieldChange
One field that differs between two vintages of the same record.
Issue
Something the loader or validator noticed, with enough context to act on it.
Lei
An ISO 17442 Legal Entity Identifier: 20 uppercase alphanumeric characters, the last two of which are ISO 7064 MOD 97-10 check digits.
LoadOptions
Inputs the CSV cannot supply for itself.
LoadOutcome
The registry, plus everything questionable found while building it.
Mic
A Market Identifier Code: four uppercase alphanumeric characters.
MicDiff
What changed between two vintages.
MicRecord
One row of the ISO 10383 registry.
MicRegistry
An immutable, in-memory index over one vintage of the ISO 10383 registry.
NoDataDir
Nothing on this platform said where a home directory is.
OperatingMic
The MIC of an operating exchange, as distinct from a segment MIC.
RecordChange
A record present in both vintages, with at least one field changed.

Enums§

IssueKind
What was wrong.
LoadError
A failure that prevents any records being read at all.
MarketCategory
The ISO 10383 market category code.
MicKind
Whether a record describes an operating exchange or one of its segments.
ParseError
Failure to parse one of this crate’s fixed-width code types.
PublishedSource
How a registry’s publication date was arrived at.
Severity
How seriously to take an Issue.
Status
The registration status of a MIC.
VintageName
What a filename says about the file.

Constants§

DATA_DIR_ENV
Overrides where fetched registries are kept and looked for.

Functions§

classify_filename
Read the convention off a path.
data_dir
Where fetched registries live.
diff
Compare two vintages.
filename_for
What diurn mic fetch names a vintage published on published.
publication_date_from_effective
The publication date implied by an effective date, if that date looks like one.
published_from_filename
The publication date a filename carries, if it carries one.
validate
Re-run the consistency checks over an already-built registry.