rust_woocommerce/config.rs
1use anyhow::Result;
2use serde::Deserialize;
3
4/// Configuration struct for storing Woo parameters
5#[derive(Deserialize)]
6pub struct Config {
7 /// The Woo struct containing ck, cs, and host strings
8 pub woo: Woo,
9}
10
11impl Config {
12 /// Create a new Config instance by reading from a file
13 ///
14 /// # Arguments
15 ///
16 /// * `file_name` - A file name (path) to read the configuration from
17 ///
18 /// # Returns
19 ///
20 /// A Result containing the Config instance if successful, or an error
21 pub fn new<T: ToString>(file_name: T) -> Result<Self> {
22 let file = std::fs::read_to_string(file_name.to_string())?;
23 let config: Config = toml::from_str(&file)?;
24 Ok(config)
25 }
26}
27/// Woo struct for storing ck, cs, and host strings
28#[derive(Deserialize)]
29pub struct Woo {
30 /// Consumer Key
31 pub ck: String,
32 /// Consumer Secret
33 pub cs: String,
34 /// Host URL
35 pub host: String,
36}