Trait settings2::Settings

source ·
pub trait Settings: 'static + Send + Sync {
    type FileContent: Clone + Default + Serialize + DeserializeOwned + JsonSchema;

    const KEY: Option<&'static str>;

    // Required method
    fn load(
        default_value: &Self::FileContent,
        user_values: &[&Self::FileContent],
        cx: &mut AppContext
    ) -> Result<Self>
       where Self: Sized;

    // Provided methods
    fn json_schema(
        generator: &mut SchemaGenerator,
        _: &SettingsJsonSchemaParams<'_>,
        _: &AppContext
    ) -> RootSchema { ... }
    fn json_merge(
        default_value: &Self::FileContent,
        user_values: &[&Self::FileContent]
    ) -> Result<Self::FileContent> { ... }
    fn load_via_json_merge(
        default_value: &Self::FileContent,
        user_values: &[&Self::FileContent]
    ) -> Result<Self>
       where Self: DeserializeOwned { ... }
    fn missing_default() -> Error { ... }
    fn register(cx: &mut AppContext)
       where Self: Sized { ... }
    fn get<'a>(path: Option<(usize, &Path)>, cx: &'a AppContext) -> &'a Self
       where Self: Sized { ... }
    fn get_global<'a>(cx: &'a AppContext) -> &'a Self
       where Self: Sized { ... }
    fn override_global<'a>(settings: Self, cx: &'a mut AppContext)
       where Self: Sized { ... }
}
Expand description

A value that can be defined as a user setting.

Settings can be loaded from a combination of multiple JSON files.

Required Associated Types§

source

type FileContent: Clone + Default + Serialize + DeserializeOwned + JsonSchema

The type that is stored in an individual JSON file.

Required Associated Constants§

source

const KEY: Option<&'static str>

The name of a key within the JSON file from which this setting should be deserialized. If this is None, then the setting will be deserialized from the root object.

Required Methods§

source

fn load( default_value: &Self::FileContent, user_values: &[&Self::FileContent], cx: &mut AppContext ) -> Result<Self>where Self: Sized,

The logic for combining together values from one or more JSON files into the final value for this setting.

The user values are ordered from least specific (the global settings file) to most specific (the innermost local settings file).

Provided Methods§

source

fn json_schema( generator: &mut SchemaGenerator, _: &SettingsJsonSchemaParams<'_>, _: &AppContext ) -> RootSchema

source

fn json_merge( default_value: &Self::FileContent, user_values: &[&Self::FileContent] ) -> Result<Self::FileContent>

source

fn load_via_json_merge( default_value: &Self::FileContent, user_values: &[&Self::FileContent] ) -> Result<Self>where Self: DeserializeOwned,

source

fn missing_default() -> Error

source

fn register(cx: &mut AppContext)where Self: Sized,

source

fn get<'a>(path: Option<(usize, &Path)>, cx: &'a AppContext) -> &'a Selfwhere Self: Sized,

source

fn get_global<'a>(cx: &'a AppContext) -> &'a Selfwhere Self: Sized,

source

fn override_global<'a>(settings: Self, cx: &'a mut AppContext)where Self: Sized,

Implementors§