Function serde_fs::from_fs[][src]

pub fn from_fs<P: AsRef<Path>, T: DeserializeOwned>(
    path: P
) -> Result<T, DeserializerError>

Deserializes a value from a file system

extern crate tempdir;
use tempdir::TempDir;
#[macro_use] extern crate serde_derive;

#[derive(Serialize, Deserialize, Debug, PartialEq)]
struct MyStruct {
  value: String,
}

extern crate serde_fs;
use serde_fs::{from_fs, to_fs};

fn main() {
  let val = MyStruct { value: "Hello".into() };
  let tmp = TempDir::new("serde_fs").unwrap();
  to_fs(tmp.path(), &val).unwrap();
  let val1: MyStruct = from_fs(tmp.path()).unwrap();
  assert_eq!(val1, val);
}