[][src]Macro agnes::spec

macro_rules! spec {
    () => { ... };
    (fieldname $field_label:ty = $header:expr; $($rest:tt)*) => { ... };
    (fieldindex $field_label:ty = $idx:expr; $($rest:tt)*) => { ... };
}

Macro for creating a source specification structure used to specify how to extract fields from a data source. It correlates labels (defined using the tablespace macro) to field / column names or indices in a data source. This source specification structure is implemented as a

The spec macro syntax is a list of fieldname or fieldindex declarations that connect field labels to either column titles or column indices (starting from 0), respectively.

Examples

This example defines a source specification with three column names: the CountryName field label will take data from the column with the "Country Name" header, the CountryCode field label will take data from the 0th (first) column, and the Gdp2015 field label will take data from the column with the "2015" label.

This example also shows the usage of the tablespace macro; see that macro's documentation for its syntax and an example.


tablespace![
    table gdp {
        CountryName: String,
        CountryCode: String,
        Gdp2015: f64,
    }
];

fn main() {
    let gdp_spec = spec![
        fieldname gdp::CountryName = "Country Name";
        fieldname gdp::CountryCode = 0usize;
        fieldname gdp::Gdp2015 = "2015";
    ];
    // ...
}