-
Notifications
You must be signed in to change notification settings - Fork 204
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
global example: Use Config::builder() for building global settings #277
base: master
Are you sure you want to change the base?
global example: Use Config::builder() for building global settings #277
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't think this example is supported without using deprecated methods. Either
- the updated example should be accepted with reduced scope/applicability to the original
- the example should be removed entirely
- the deprecation of the
Config::set
method should be revisited
// Set property | ||
SETTINGS.write()?.set("property", 42)?; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't think these two versions are equivalent. the existing example is mutable global configuration, the second is immutable global configuration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, AFAICS, my change is equivalent, because Config::set
sets a default internally, which is now done via ConfigBuilder::set_default()
. Mutability is still provided, as the resulting Config
object is still in a RwLock
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though, mutability on the Config
object is not needed anymore, because there are no (non-deprecated) methods that take &mut self
!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure that's correct? Looks to me like Config::set
sets an override, not a default. Thus it can be used for modifying the config after it's been parsed (as is done in the example).
Without using deprecated methods, it's not possible to modify the Config
after its construction, since as you say, there are no methods that take &mut self
. That also makes the RwLock redundant.
As far as I can tell, before the deprecation it was possible to modify global configuration programatically after its construction, and after deprecating the methods it is not. It could well be that this was intentional, but it does mean that some use-cases (including one this example demonstrates) are no longer possible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm. Yes, you're right. Lets see what @szarykott says, but I guess we should re-think the deprecation (as you said)! 👍
@szarykott I guess your input on this matter would be valuable! |
I just tried to bump this crate in a project of mine and got completely hung up. I eventually came around looking for examples and eventually found this PR. I'm going to back off and just hold it back a version for now because it looks like my entire use case is dependent on something that went away. |
@alerque I am sorry to read that we broke your usecase! Is your code open source and could you point us to it, so we can understand what we broke and ideally how we can fix our side to make your experience good again? |
Thanks for the reply @matthiasbeyer. I have several open source and some more private projects that I've used the same general paradigm for. It's possible I've just over complicated things by not understanding the other possible ways to set this up, but here is one example of what I'm doing: https://github.com/sile-typesetter/casile/blob/master/src/config.rs The resulting mutable state https::/github.com/sile-typesetter/casile/blob/master/src/main.rs#L9-L15 Other places If there is a way to code this that can handle the multi-threaded access with a set of defaults and the ongoing mutability through the life cycle then I'm open to adapting. |
I don't see why you would have your configuration in a global variable? Having it initialized in |
No. That's what I started out trying to do, but besides being a royal pain to pass around all the time, I couldn't find a way to do so that allowed the configuration to be mutable from threads (rayon) that didn't run into lifetime issues. |
Hm. What were you trying to pass around exactly? An |
Hello, we are trying to bump the version to 0.12 but our case doesn't seem to be easy to port. What we did before was more or less: let mut config = Config::default();
try merging with a File or ignore
try merging with another File or ignore
return config the "try merging part" is very clunky: let mut tmp = Config::default();
if tmp.merge(file source).is_err() { ignore ... }
else {
config.merge(file source);
} I tried porting this to 0.12 and while doable, the lack of ability to mark certain sources as optional is making life hard. Furthermore, the lack of integration with std is making the whole process more complicated than it should be. For instance, why not implement The Config object once constructed is very useful, but getting it constructed can be a pain. p.s. where did get_str() go :( |
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
1eff7b3
to
a00ff89
Compare
Rebased and fixed the formatting issue here. If we still want this, CI should be green now. |
@danieleades your review would be appreciated (submitted seperately instead of adding it to #262)