chshersh / tool-sync

🧰 Download pre-built binaries of all your favourite tools with a single command
https://crates.io/crates/tool-sync
Mozilla Public License 2.0
69 stars 16 forks source link

Provide more detailed TOML decoding errors #122

Closed DukeManh closed 1 year ago

DukeManh commented 1 year ago

Fixes #25

Provide more detailed TOML decoding errors by adding DecodeError enum to represent different error types.

Author's questions:

Does the toml crate provide better decoding than as_str() and friends? All such functions return Option<...> while it would be better to have Result<..., ...>

I couldn't find better decoding than asstr() but I did map Option<> to `Result<, DecodeError>` so I guess dealing with Option is fine?

Additional tasks

DukeManh commented 1 year ago

@chshersh That's a great suggestion, I'm on it.

DukeManh commented 1 year ago

I have some questions.

Introduce a separate data type for TOML value types

Why do we need a separate type for toml and not use toml::value?

we want to return all possible errors at once.

Is it something you have in mind? https://doc.rust-lang.org/rust-by-example/error/multiple_error_types.html

chshersh commented 1 year ago

Why do we need a separate type for toml and not use toml::value?

toml::Value also stores data inside. When we decode TOML, we don't expect any specific data, we expect only the shape of Data. So, unfortunately, we can't reuse toml::Value here.

Is it something you have in mind? https://doc.rust-lang.org/rust-by-example/error/multiple_error_types.html

No, more like something similar:

DukeManh commented 1 year ago

@chshersh this is ready, can you review it, please?

DukeManh commented 1 year ago

@chshersh, I decided to reuse toml::Value and type_str to represent our expected type. What do you think?