Crate papyrus_config

Source
Expand description

Configuration utilities for a Starknet node.

§Example

use std::collections::BTreeMap;
use std::fs::File;
use std::path::Path;

use clap::Command;
use papyrus_config::dumping::{ser_param, SerializeConfig};
use papyrus_config::loading::load_and_process_config;
use papyrus_config::{ParamPath, ParamPrivacyInput, SerializedParam};
use serde::{Deserialize, Serialize};
use tempfile::TempDir;

#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
struct ConfigExample {
    key: usize,
}

impl SerializeConfig for ConfigExample {
    fn dump(&self) -> BTreeMap<ParamPath, SerializedParam> {
        BTreeMap::from([ser_param(
            "key",
            &self.key,
            "This is key description.",
            ParamPrivacyInput::Public,
        )])
    }
}

let dir = TempDir::new().unwrap();
let file_path = dir.path().join("config.json");
ConfigExample { key: 42 }.dump_to_file(&vec![], file_path.to_str().unwrap());
let file = File::open(file_path).unwrap();
let loaded_config = load_and_process_config::<ConfigExample>(
    file,
    Command::new("Program"),
    vec!["Program".to_owned(), "--key".to_owned(), "770".to_owned()],
)
.unwrap();
assert_eq!(loaded_config.key, 770);

Modules§

converters
Utils for serialization and deserialization of nested config fields into simple types. These conversions let the command line updater (which supports only numbers strings and booleans) handle these fields.
dumping
Utils for serializing config objects into flatten map and json file. The elements structure is:
loading
Loads a configuration object, and set values for the fields in the following order of priority:
presentation
presentation of a configuration, with hiding or exposing private parameters.
validators
Utils for config validations.

Structs§

SerializedParam
A description and serialized content of a configuration parameter.

Enums§

ConfigError
Errors at the configuration dumping and loading process.
ParamPrivacyInput
The privacy level of a config parameter, that received as input from the configs.
SerializationType
A serialized type of a configuration parameter.
SerializedContent
A serialized content of a configuration parameter.

Type Aliases§

Description
A description of a configuration parameter.
ParamPath
A nested path of a configuration parameter.