Skip to main content

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 std::io::{Read, Seek};
4
5pub use serde_json::Value as Settings;
6
7pub trait ParseSettings: Sized {
8    type Error;
9    fn parse_settings(settings: Settings) -> Result<Self, Self::Error>;
10}
11
12/// An error parsing a settings file
13#[derive(Debug, thiserror::Error)]
14#[non_exhaustive]
15pub enum SettingsError {
16    /// Incorrect Plist syntax
17    #[error("Incorrect Plist syntax: {0}")]
18    Plist(#[source] Box<dyn std::error::Error + Send + Sync>),
19}
20
21pub fn read_plist<R: Read + Seek>(reader: R) -> Result<Settings, SettingsError> {
22    let settings = plist::from_reader(reader).map_err(|e| SettingsError::Plist(Box::new(e)))?;
23    Ok(settings)
24}