WIP: config: Type safe API prototype

If we represent settings with types, we can provide an api to
get/set/monitor settings that guarantees we can only access settings
that exist with the right types, without seperate getter/setter/callback
functions like GTK would use.
This commit is contained in:
Ian Douglas Scott 2023-07-05 16:45:16 -07:00
parent 456b2ddcd5
commit 5c5460e93c
3 changed files with 65 additions and 0 deletions

View file

@ -0,0 +1,27 @@
use cosmic_config::setting::{App, Setting, AppConfig};
struct ExampleApp;
impl App for ExampleApp {
const ID: &'static str = "com.Example.App";
const VERSION: u64 = 1;
}
struct DoFoo;
impl Setting<ExampleApp> for DoFoo {
const NAME: &'static str = "do-foo";
type Type = bool;
}
struct WhatBar;
impl Setting<ExampleApp> for WhatBar {
const NAME: &'static str = "what-bar";
type Type = String;
}
fn main() {
let config = AppConfig::<ExampleApp>::new().unwrap();
config.set::<DoFoo>(true).unwrap();
}