Function serde_any::from_file_stem [−][src]
pub fn from_file_stem<T, P>(stem: P) -> Result<T, Error> where
T: DeserializeOwned,
P: AsRef<Path>,
Deserialize from any file with a given stem
This function tries to deserialize from any file with stem stem
and any of the supported extensions.
The list of supported extensions can be queried with supported_extensions
.
Errors
If none of the supported formats can deserialize the string successfully,
Error::NoSuccessfulParse
is returned.
Example
#[macro_use] extern crate serde; extern crate serde_any; #[derive(Deserialize, Debug)] struct User { fingerprint: String, location: String, } fn main() { // Will attempt "user.json", "user.yaml", "user.toml" and "user.ron" // If any of the features is disabled, that extension is skipped match serde_any::from_file_stem::<User, _>("user") { Ok(u) => println!("{:#?}", u), Err(e) => println!("Error deserializing user: {}", e), }; }