The Display string for DeviceState::FailFast is "failfast" instead of "fail_fast", the same as its value for parsing in FromStr. If it's not acceptable, please let me know and I will come back the explicit implementation.
Note:
Unfortunately, I've overestimated the power of the strum crate. It has a lot of limitations (at least for now), therefore I've kept explicit impls in some cases.
It seems I can't specify different attributes for serialization and deserializaition like "failfast" and "fail_fast" for DeviceState::FailFast, despite I don't see the issue for it.
Second commit: Use thiserror crate for errors
Changes:
Use derives of thiserror to avoid explicit impl Error, impl Display, impl From<OtherError> and so on.
This change also allows to use strum for a bit more enums
This commit is not in the scope of initial issue, so I will revert it if you want.
Checks:
Current tests are Ok (but seems they don't use the changed functionality)
I've manually checked the accuracy of changes in terms of the same strings before and after these changes.
I use the fork with these changes in our project, and its tests are passed
If you think that this PR can't be merged without adding new tests let me know.
Also it would be great to release a new version of block-utils after merging this PR due to changes in #25
The goal of this PR is refactoring to avoid boilerplate in enums implementation.
First commit: Use
strum
crate for enumsChanges:
impl Display
withstrum::Display
impl FromStr
withstrum::EnumString
impl From<Enum> for &'static str
withstrum::IntoStaticStr
strum::ParseError
Changes in public interface:
FromStr
isstrum::ParseError
instead ofBlockUtilsError(String)
. The reason is current limitation instrum
, see https://github.com/Peternator7/strum/issues/91Display
string forDeviceState::FailFast
is "failfast" instead of "fail_fast", the same as its value for parsing in FromStr. If it's not acceptable, please let me know and I will come back the explicit implementation.Note:
strum
crate. It has a lot of limitations (at least for now), therefore I've kept explicit impls in some cases.Second commit: Use
thiserror
crate for errors Changes:thiserror
to avoid explicitimpl Error
,impl Display
,impl From<OtherError>
and so on.strum
for a bit more enumsThis commit is not in the scope of initial issue, so I will revert it if you want.
Checks:
Also it would be great to release a new version of
block-utils
after merging this PR due to changes in #25Close #26