Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AvdanOS Configuration Pt. II #53

Merged
12 commits merged into from
Sep 10, 2022
Merged

AvdanOS Configuration Pt. II #53

12 commits merged into from
Sep 10, 2022

Conversation

Sammy99jsp
Copy link
Member

@Sammy99jsp Sammy99jsp commented Sep 10, 2022

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";
}
  1. Adding it to the Config struct somewhere:
#[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

  • Config macros automatically generate JSON Schemas, and default JSONC sections.
  • Build script packages them together, to be bundled with a release.

@Sammy99jsp Sammy99jsp added enhancement New feature or request configuration labels Sep 10, 2022
@Sammy99jsp Sammy99jsp requested a review from a user September 10, 2022 00:31
@Sammy99jsp Sammy99jsp linked an issue Sep 10, 2022 that may be closed by this pull request
@Sammy99jsp Sammy99jsp requested a review from Froxcey September 10, 2022 00:59
Copy link
Contributor

@Froxcey Froxcey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, learned a lot from this

vibe

Copy link
Contributor

@Froxcey Froxcey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

vibe

@Froxcey
Copy link
Contributor

Froxcey commented Sep 10, 2022

lmao I thought my review didn't sent

@MrSerge01
Copy link
Contributor

lmao

@MrSerge01
Copy link
Contributor

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

@ghost ghost merged commit b8f0784 into Avdan-OS:dev Sep 10, 2022
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
configuration enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compositor Configuration: AvConfig macro
3 participants