-
-
Notifications
You must be signed in to change notification settings - Fork 144
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- The
tag
module is private to the crate. I think theNbtType
trait and the generic type parameter onInvalidTypeError
should be removed to keep the interface as simple as possible. InvalidTypeError
is missing astd::error::Error
impl.- If
TryFrom<Value> for T
exists, it would make sense to me thatTryFrom<&Value> for &T
andTryFrom<&mut Value> for &mut T
should also exist. - It is worth looking at
serde_json::Value
. Notably, it does not have any trait impls to doValue
toT
conversions. 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! |
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 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
None
butResult<>
with the old value if the type did not match the desired type.Related: #145 (comment)