-
Notifications
You must be signed in to change notification settings - Fork 0
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
Proposal: Merge efforts with config-rs #1
Comments
Hey @mehcode, Appreciate you taking the time for this proposal. I agree that there's much overlap. One of my motivations was to remove the need for stringly-typed key names. Macros allowed for this but introduced other issues like requiring serde as an explicit dependency for clients. But the second snippet you showed that allows defaults to be embedded directly into the struct looks very interesting! I hadn't come across that before and it looks like it would achieve what I intended this crate to be. I'm not sure if this crate would serve much purpose after that feature has been merged, assuming it supports nested structs. Until then, I'm quite torn on if this crate is more of a I'll give it a whirl. Keen to hear if you have any thoughts on implementation or anything I've mentioned. |
@kwyse I had an idea. I'm assuming the motivation for this crate stems from a large usability gap from simple defaults to complex defaults? For example .. #[derive(Default)]
struct Foo { bar: i32 } The above works if you want struct Foo { bar: i32 }
impl Default for Foo {
fn default() -> Self {
Foo { bar: 4 }
}
} This issue is most apparent with enumerations as What about renaming this crate to default2 and rewriting your macro with a proc derive macro? You could make the following API work: #[derive(Default2)]
#[default = "Red"]
enum Color { Red, Green, Blue }
#[derive(Default2)]
struct Foo {
#[default = 4]
bar: u32,
color: Color
} The idea is it would generate Furthermore, after this crate is done (as a proof of concept), It'd be interesting to see if something like this could be accepted as an RFC to improve the default I'd use the heck out of something like this. |
@mehcode I really like this idea! I've changed the crate to be a proc macro and implemented a very bare bones version of what you've said in 23da178. Only structs are supported for now but I will implement enums next. References to configuration have been removed. I'll rename the project shortly. I think it makes sense for this project to remain strictly to override the default values of the |
@kwyse there is a crate with a similar (but not the same) purpose: https://github.com/nrc/derive-new. You can try to pick some ideas from there. |
Thanks @hcpl. From a quick look it seems like |
@kwyse sure, the functionality between two crates overlaps very much, but there is definitely a use-case for your crate: when something requires a value of type |
Nice crate. I like the idea for a quick method of defaulting some a config struct. However, there seems to be a lot of overlap on functionality in
config-rs
. Would you like to come join us atconfig-rs
and work on this problem space together?config-rs
is tagged as a configurable configuration library. The idea is for it to support as many possible variants of configuration as possible but to do nothing unless asked.When merging values on top of defaults,
config-rs
currently does support JSON, YAML, and TOML; as well as, environment variables. I've plans to support many more formats.For an example, here is the Usage example in your readme implemented in two different ways.
One possible currently in config-rs:
And one possible soon in Serde directly you might not have seen:
I could help you utilize
config
internally in this crate if you'd like to keep the macro syntax (it is a bit cleaner for the non-nested struct case). In any case, the more eyes and focus we can get on a common core of configuration utilities, the better.The text was updated successfully, but these errors were encountered: