ixa::global_properties

Trait ContextGlobalPropertiesExt

Source
pub trait ContextGlobalPropertiesExt {
    // Required methods
    fn set_global_property_value<T: GlobalProperty + 'static>(
        &mut self,
        property: T,
        value: T::Value,
    ) -> Result<(), IxaError>;
    fn get_global_property_value<T: GlobalProperty + 'static>(
        &self,
        _property: T,
    ) -> Option<&T::Value>;
    fn list_registered_global_properties(&self) -> Vec<String>;
    fn get_serialized_value_by_string(
        &self,
        name: &str,
    ) -> Result<Option<String>, IxaError>;
    fn load_parameters_from_json<T: 'static + Debug + DeserializeOwned>(
        &mut self,
        file_path: &Path,
    ) -> Result<T, IxaError>;
    fn load_global_properties(
        &mut self,
        file_name: &Path,
    ) -> Result<(), IxaError>;
}

Required Methods§

Source

fn set_global_property_value<T: GlobalProperty + 'static>( &mut self, property: T, value: T::Value, ) -> Result<(), IxaError>

Set the value of a global property of type T

§Errors

Will return an error if an attempt is made to change a value.

Source

fn get_global_property_value<T: GlobalProperty + 'static>( &self, _property: T, ) -> Option<&T::Value>

Return value of global property T

Source

fn list_registered_global_properties(&self) -> Vec<String>

Source

fn get_serialized_value_by_string( &self, name: &str, ) -> Result<Option<String>, IxaError>

Return the serialized value of a global property by fully qualified name

§Errors

Will return an IxaError if the property does not exist

Source

fn load_parameters_from_json<T: 'static + Debug + DeserializeOwned>( &mut self, file_path: &Path, ) -> Result<T, IxaError>

Given a file path for a valid json file, deserialize parameter values for a given struct T

§Errors

Will return an IxaError if the file_path does not exist or cannot be deserialized

Source

fn load_global_properties(&mut self, file_name: &Path) -> Result<(), IxaError>

Load global properties from a JSON file.

The expected structure is a dictionary with each name being the name of the struct prefixed with the crate name, as in: ixa.NumFluVariants and the value being an object which can serde deserialize into the relevant struct.

§Errors

Will return an IxaError if:

  • The file_path doesn’t exist
  • The file isn’t valid JSON
  • A specified object doesn’t correspond to an existing global property.
  • There are two values for the same object.

Ixa automatically knows about any property defined with define_global_property!() so you don’t need to register them explicitly.

It is possible to call Context::load_global_properties() multiple times with different files as long as the files have disjoint sets of properties.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§