[#4] Added from_config_file constructor to Tavern.
This commit is contained in:
@ -25,3 +25,20 @@ pub struct Tavern
|
||||
/// A list of all adventurers (authors) who have contributed tales.
|
||||
pub authors: Vec<Adventurer>
|
||||
}
|
||||
|
||||
|
||||
|
||||
impl Tavern
|
||||
{
|
||||
#[cfg(feature = "publisher")]
|
||||
pub fn from_config_file<P>(config_file: P) -> Self
|
||||
where P: AsRef<std::path::Path>
|
||||
{
|
||||
// Read the previously written TOML file
|
||||
let toml_data =
|
||||
std::fs::read_to_string(&config_file).expect("Failed to read TOML file");
|
||||
|
||||
// Deserialize it
|
||||
toml::from_str(&toml_data).expect("Failed to parse TOML")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user