Struct Context

Source
pub struct Context {
    pub name: String,
    pub product_root: Option<PathBuf>,
    pub data_root: Option<PathBuf>,
    pub settings: MicroDataCollection,
    pub allow_full_metadata: bool,
    pub enable_full_metadata: bool,
}
Expand description

Holds loaded metadata and information for finding data and additional metadata.

This mutable state holds loaded metadata (if any), the rest of the information needed to add paths to the data tables used in queries and data file paths, and information about where the metadata can be found.

Often, creating a DataRequest will automatically return a Context along with the DataRequest (for example, see DataRequest::from_names and AbacusRequest::try_from_json). In those cases, you do not need to directly create a context yourself. If you do find yourself needing to directly create a Context, from_ipums_collection_name is the easiest way to do that.

use cimdea::conventions::Context;

// Set data root to point to the directory with your data
let data_root = "tests/data_root/".to_string();
let ctx = Context::from_ipums_collection_name(
  "usa",
  None,
  Some(data_root),
).unwrap();

assert_eq!(ctx.name, "usa");
let mut record_types: Vec<_> = ctx.settings.record_types.keys().collect();
record_types.sort();
assert_eq!(record_types, ["H", "P"]);

Fields§

§name: String

A product name like USA, IPUMSI, CPS etc

§product_root: Option<PathBuf>§data_root: Option<PathBuf>

Any output_data/current path with ./layouts and ./parquet in it

§settings: MicroDataCollection§allow_full_metadata: bool§enable_full_metadata: bool

Implementations§

Source§

impl Context

Source

pub fn get_md_variable_by_name( &self, name: &str, ) -> Result<IpumsVariable, MdError>

Source

pub fn paths_from_dataset_name( &self, dataset_name: &str, data_format: &InputType, ) -> Result<HashMap<String, PathBuf>, MdError>

Formats the exact paths needed to get data for this dataset, by record type.

Source

pub fn load_metadata_for_datasets( &mut self, datasets: &[&str], ) -> Result<(), MdError>

When called, the context should be already set to read from layouts or full metadata

Source

pub fn load_metadata_for_datasets_and_variables( &mut self, _datasets: Vec<String>, _variables: Vec<String>, )

The context should be set to read from layouts or full metadata

Source

pub fn from_ipums_collection_name( name: &str, other_product_root: Option<String>, other_data_root: Option<String>, ) -> Result<Self, MdError>

Based on name, use default data root and product root and initialize with defaults Optional data root and product root will be used if provided.

Returns an error if the given name isn’t the name of a recognized product.

Trait Implementations§

Source§

impl Clone for Context

Source§

fn clone(&self) -> Context

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Context

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,