-
Notifications
You must be signed in to change notification settings - Fork 96
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
Generic Value parsing #572
Comments
We have a You might also find what cargo does interesting. Cargo allows applying configs of the format |
That is pretty close to what I'm looking for. The one difference being that doing let val = "true";
val.parse::<toml::Value>(); // would yield toml::Value(Boolean(true))
let val = "64";
val.parse::<toml::Value>(); // would yield toml::Value(Integer(64))
let val = "foo";
val.parse::<toml::Value>(); // would yield toml::Value(String("foo")) However, the approach that you outlined is fine. I was just wondering if I could avoid having my users type Cargo's approach does look interesting though. If I am understanding the code correctly, it's basically loading an already defined config file and just overriding the provided values correct? |
imo that is a bug that In the mean time, you can workaround it with https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=c24e42a886c7c417c8ac9b6cfbcac250. The main problem is strings will need to be quoted. |
Cool beans, that will do just fine for the time being. By the way, thank you for the quick responses! They are greatly appreciated. |
Is it still not fixed? Recently had the problem. We can do Of couse based on your example the workaround |
It was waiting on a breaking release but I lost track of outstanding breaking changes. However, the most recent breaking release is recent enough that we could likely do a new one with minimal disruption. |
Oh, I overlooked that this was for the |
For context, I am writing a command line application that provides configuration support via a TOML file. Much like how Git provides the
config
command to set config values, my app will do the same. I am wondering what the best way is to parse user input to a validtoml::Value
(for example, if the user provides "true" it should be parsed toValue::Boolean(true)
).What I ended up doing is something along these lines:
which seems rather hacky, imo. I was hoping that this method would be available on the enum already, but it does not appear to be.
Would it be possible implement a method similar to this on the
Value
enum? I imagine it would return aResult
instead of the actual instance, but it would be a nice convenience method.Having skimmed the value.rs file, it looks rather easy to add but that might just be my naivety.
The text was updated successfully, but these errors were encountered: