Enforce (at compile-time) that imageops::filter3x3()
is provided an array of length 9
#2600
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.
This PR was made in response to #2599 (comment).
This PR contains a breaking change, and thus should not be included until the next major version.
This changes the function signature of
crate::imageops::filter3x3()
(and its accompanying function inDynamicImage
). Rather than take a&[f32]
as before, now it takes a&[f32; 9]
, enforcing that the kernel provided is of length 9 in a much more user-friendly way.Notably, not every user of
filter3x3()
will need to explicitly convert thekernel
they provide. For example, one test inimage
contains this line, which didn't need to be changed:image/src/images/dynimage.rs
Line 2230 in ceb71e5
But for those that do, the
TryFrom<&[T]> for &[T; N]
impl (provided by the Rust standard library) will fit most (if not all) cases.slice::as_array()
is also available if the user is on nightly.In summary:
crate::imageops::filter3x3()
no longer assumes the kernel is of length 9 (it appears to have done so before, without giving any form of error)DynamicImage::filter3x3()
now errors at compile-time if given the wrong length, rather than checking at run-time and stopping the program there.filter3x3()
may need to modify their code to handle the new type signature. However, in most cases the solution is simple, and provided by the Rust standard library.