Avdan-OS / Compositor

Rusty AvdanOS Wayland compositor
GNU General Public License v3.0
22 stars 11 forks source link

AvdanOS Configuration Pt. II #53

Closed Sammy99jsp closed 1 year ago

Sammy99jsp commented 1 year ago

Associated Issues: #46 #23

The main changes are the continuation of the custom Syntax from my first repo.

Adding a custom section

Now, implementing a configuration section is as simple as:

  1. Declaring it:
    
    use compositor_macros::config_section;

use crate::config::ConfigurationSection;

config_section!( MyCustomSection { "How many horns does a unicorn have?" unicornHorns => 1, } );

impl ConfigurationSection for MyCustomSection { const PATH : &'static str = "$.myCustomSection"; }


2. Adding it to the `Config` struct somewhere:
```rust
#[derive(Deserialize, Debug)]
pub struct Config {
    /* . . . . */
    pub my_custom_section: MyCustomSection
}

And that's it!

Using the Config

The config can be gotten anywhere after initialization with Config::config(). Paths are also accessible if they are declared appropriately in their sections:

let config = Config::config();
println!("Horns on a unicorn: {}", config.my_custom_section.unicornHorns);

Future plans

Froxcey commented 1 year ago

lmao I thought my review didn't sent

MrSerge01 commented 1 year ago

lmao

MrSerge01 commented 1 year ago

@Sammy99jsp btw, if you have more work to do with this, it's great to make this a draft PR