pub fn create_cargo_lib(
    lss: &'static dyn LocalSecureStorage,
    cfg: CargoConfig
) -> Result<Arc<Mutex<CargoLib>>, SingleVariantError<CargoLibCreationError>>
Expand description

CargoLib initializer which is the main part of Cargo public API. All functionalities are exposed to application side through this structure.

Underlying structure is created only once, subsequent call will return handle to the same structure.

It requires the following arguments:

  • lss: some type implementing LocalSecureStorage trait. It is usually provided by the native to a target platform language. It is assumed that a lss reference should be valid for a whole program execution (static lifetime).
  • cfg: CargoConfig structure with config variables (logger, endpoints, etc.)

CargoLib expects to get references with static lifetimes so it is important not to inline objects (e.g. LSS) initialization along with createCargoLib call.

struct TestLss{};

impl LocalSecureStorage for TestLss {
// ...implementation here
}

let lss = TestLss{};

let cfg = CargoConfig{     
    logger_config: LoggerConfig {
        use_logger: true,
        log_level: Level::TRACE,
        log_use_ansi: false,
        log_file_path: PathBuf::from("cargo_lib_log"),
        log_file_rotate_directory: PathBuf::from(".".to_owned()),
        log_file_enabled: true,
        oslog_category: None,
        oslog_subsystem: None,
    },
    fsa_config: FoundationStorageApiConfig {
        evs_url: "some_url".to_owned(),
        sc_url: "some_url".to_owned(),
    },
};

let lss: &'static TestLss = unsafe { std::mem::transmute(&lss) };
let cargo_lib = create_cargo_lib(lss, cfg);