Re-visit From impl for native data types found in NBT data format. - #169
Conversation
Now no longer returns `None` but `Result<>` with the old value if the type did not match the desired type.
There was a problem hiding this comment.
- The
tagmodule is private to the crate. I think theNbtTypetrait and the generic type parameter onInvalidTypeErrorshould be removed to keep the interface as simple as possible. InvalidTypeErroris missing astd::error::Errorimpl.- If
TryFrom<Value> for Texists, it would make sense to me thatTryFrom<&Value> for &TandTryFrom<&mut Value> for &mut Tshould also exist. - It is worth looking at
serde_json::Value. Notably, it does not have any trait impls to doValuetoTconversions. The closest thing is theas_*methods.
To avoid the above problems, I think it would be best to just remove all the TryFrom<Value> for T and From<Value> for Option<T> impls on Value and recreate the needed conversion functions in valence_anvil. Or create an analogue of the as_* functions if that proves sufficient for your needs.
|
Have a look at the latest change. I have ditched all generics and hard-coded the value conversions as seen in serde. It created the following methods:
IntelliJ IntelliSense works for all of the methods defined in the macro. |
|
Woops, I wanted to rename the branch. Guess not! |
rj00a
left a comment
There was a problem hiding this comment.
I think the take_* functions should be renamed to into_* since "take" implies that the argument is not consumed. Other than that, looks good to me.
Now no longer returns
NonebutResult<>with the old value if the type did not match the desired type.Related: #145 (comment)