1 /// Code based on https://github.com/defuz/sublimate/blob/master/src/core/settings.rs
2 /// released under the MIT license by @defuz
3 
4 use std::io::{Read, Seek};
5 use plist::{Error as PlistError};
6 
7 pub use serde_json::Value as Settings;
8 pub use serde_json::Value::Array as SettingsArray;
9 pub use serde_json::Value::Object as SettingsObject;
10 
11 pub trait FromSettings: Sized {
from_settings(settings: Settings) -> Self12     fn from_settings(settings: Settings) -> Self;
13 }
14 
15 pub trait ParseSettings: Sized {
16     type Error;
parse_settings(settings: Settings) -> Result<Self, Self::Error>17     fn parse_settings(settings: Settings) -> Result<Self, Self::Error>;
18 }
19 
20 
21 /// An error parsing a settings file
22 #[derive(Debug)]
23 pub enum SettingsError {
24     /// Incorrect Plist syntax
25     Plist(PlistError),
26 }
27 
28 impl From<PlistError> for SettingsError {
from(error: PlistError) -> SettingsError29     fn from(error: PlistError) -> SettingsError {
30         SettingsError::Plist(error)
31     }
32 }
33 
read_plist<R: Read + Seek>(reader: R) -> Result<Settings, SettingsError>34 pub fn read_plist<R: Read + Seek>(reader: R) -> Result<Settings, SettingsError> {
35     let settings = plist::from_reader(reader)?;
36     Ok(settings)
37 }
38