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§
- 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.
- Utils for serializing config objects into flatten map and json file. The elements structure is:
- Loads a configuration object, and set values for the fields in the following order of priority:
- presentation of a configuration, with hiding or exposing private parameters.
- Utils for config validations.
Structs§
- A description and serialized content of a configuration parameter.
Enums§
- Errors at the configuration dumping and loading process.
- The privacy level of a config parameter, that received as input from the configs.
- A serialized type of a configuration parameter.
- A serialized content of a configuration parameter.
Type Aliases§
- A description of a configuration parameter.
- A nested path of a configuration parameter.