Skip to main content

Crate xbrlkit_derive

Crate xbrlkit_derive 

Source
Expand description

#[derive(FromXbrl)] for xbrlkit.

Binds the fields of a struct to XBRL concepts. The binding lives in #[xbrl(..)] attributes and nowhere else, so the struct’s serde names stay its Rust names — which is what reaches JSON, Arrow and Parquet.

Depend on xbrlkit and use the derive it re-exports; this crate is not meant to be used on its own, and the code it generates refers to ::xbrlkit.

ⓘ
use xbrlkit::FromXbrl;

#[derive(Default, FromXbrl)]
#[xbrl(instant)]
pub struct BalanceSheet {
    /// The date the figures are as of.
    #[xbrl(period_end)]
    pub as_of: Option<String>,

    #[xbrl(concept = "us-gaap:Assets")]
    pub assets: Option<f64>,

    /// The first concept the filing reports wins.
    #[xbrl(concept = "us-gaap:Liabilities", alias = "us-gaap:LiabilitiesNoncurrent")]
    pub liabilities: Option<f64>,
}

§Field attributes

AttributeThe field is
concept = ".." [, alias = ".."]…read from these concepts, in order of preference
nestedanother FromXbrl struct, read in the same scope
each_perioda Vec of a FromXbrl struct, one per reported period
period_start / period_endthe dates of the period the struct was read for
(none)left at its Default

What a concept field holds is decided by its type — see xbrlkit::bind::FromFacts.

§Struct attributes

#[xbrl(instant)] or #[xbrl(duration)] says which kind of period the struct’s concepts are reported for, so that each_period does not produce a balance sheet for a quarter or an income statement for a date.

Derive Macros§

FromXbrl
Derives xbrlkit::FromXbrl for a struct with named fields. See the crate docs.