pub struct Configs { /* private fields */ }
Implementations§
Source§impl Configs
impl Configs
Sourcepub fn new(path: &String) -> Configs
pub fn new(path: &String) -> Configs
Constructs a new Configs
§Arguments
- `path: &String - The full path name (including the file name and extension) to the configuration file.
#Example
extern crate test_data_generation;
use test_data_generation::configs::Configs;
fn main() {
// initalize a new Configs
let mut cfg = Configs::new(&String::from("./tests/config/tdg.yaml"));
cfg.load_config_file();
// verify the configuration file has been loaded
println!("{:?}", cfg);
}
Sourcepub fn from_serialized(serialized: &str) -> Configs
pub fn from_serialized(serialized: &str) -> Configs
Constructs a new Configs object from a serialized (JSON) string. This is used when restoring from “archive”
#Example
extern crate test_data_generation;
use test_data_generation::configs::Configs;
fn main() {
let serialized = "{\"file\":\"./tests/config/tdg.yaml\"}";
let mut cfg = Configs::from_serialized(&serialized);
assert_eq!(cfg.get_config_file_path(), "./tests/config/tdg.yaml");
}
Sourcepub fn get_config_file_path(&self) -> &str
pub fn get_config_file_path(&self) -> &str
Loads the configuration file using the path that was provided during calling a new Configs object
#Example
extern crate test_data_generation;
use test_data_generation::configs::Configs;
fn main() {
// initalize a new Configs
let mut cfg = Configs::new(&String::from("./tests/config/tdg.yaml"));
// verify the configuration file path was set
println!("The configuration fiel is located at {}", cfg.get_config_file_path());
}
Sourcepub fn load_config_file(&mut self)
pub fn load_config_file(&mut self)
Loads the configuration file using the path that was provided during calling a new Configs object
#Example
extern crate test_data_generation;
use test_data_generation::configs::Configs;
fn main() {
// initalize a new Configs
let mut cfg = Configs::new(&String::from("./tests/config/tdg.yaml"));
cfg.load_config_file();
// verify the configuration file has been loaded
println!("{:?}", cfg);
}
Sourcepub fn serialize(&mut self) -> String
pub fn serialize(&mut self) -> String
This function converts the Configs object to a serialize JSON string.
#Example
extern crate test_data_generation;
use test_data_generation::configs::Configs;
fn main() {
//create a Configs object from a configuration file
let mut cfg = Configs::new(&String::from("./tests/config/tdg.yaml"));
cfg.load_config_file();
println!("{}", cfg.serialize());
// {"key":"r","prior_key":null,"next_key":null,"pattern_placeholder":"c","starts_with":0,"ends_with":0,"index_offset":2}
}
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Configs
impl<'de> Deserialize<'de> for Configs
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Configs
impl RefUnwindSafe for Configs
impl Send for Configs
impl Sync for Configs
impl Unpin for Configs
impl UnwindSafe for Configs
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more