syntect/highlighting/
settings.rs

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