Implement From trait for cpVect ⟷ tuple and array #5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I have implemented the standard From trait for converting a
cpVect
or&cpVect
into a(cpFloat, cpFloat)
tuple or[cpFloat; 2]
array, which are the same as(f64, f64)
and[f64; 2]
. I have also implemented the trait for the opposite direction, converting a tuple or array into a cpVect. This makes it very easy to convert back and forth, which can simplify a lot of code in the chipmunk crate, or anyone who uses the chipmunk-sys crate directly.Implementing the From trait also gives us the Into trait automatically.
This makes the
cpVect::to_tuple()
function obsolete. You can writev.into()
or<(f64, f64)>::from(v)
instead ofv.to_tuple()
. I have markedcpVect::to_tuple()
as deprecated. It doesn't exist in any released version of this crate, but it is used by the master branch of the chipmunk crate, so I didn't want to remove it completely yet.This pull request is based on the commits in pull request #2. I recommend merging that pull request first.