Skip to content

Commit 4589a4a

Browse files
dzfriaskornelski
authored andcommitted
Add #[must_use] attribute to some DynamicImage methods
This is an API improvement to make it clear to users that most of the methods on `DynamicImage` are non-mutating.
1 parent 84fd828 commit 4589a4a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/dynimage.rs

+19
Original file line numberDiff line numberDiff line change
@@ -384,11 +384,13 @@ impl DynamicImage {
384384
///
385385
/// Note: this method does *not* modify the object,
386386
/// and its signature will be replaced with `crop_imm()`'s in the 0.24 release
387+
#[must_use]
387388
pub fn crop(&mut self, x: u32, y: u32, width: u32, height: u32) -> DynamicImage {
388389
dynamic_map!(*self, ref mut p => imageops::crop(p, x, y, width, height).to_image())
389390
}
390391

391392
/// Return a cut-out of this image delimited by the bounding rectangle.
393+
#[must_use]
392394
pub fn crop_imm(&self, x: u32, y: u32, width: u32, height: u32) -> DynamicImage {
393395
dynamic_map!(*self, ref p => imageops::crop_imm(p, x, y, width, height).to_image())
394396
}
@@ -653,6 +655,7 @@ impl DynamicImage {
653655
/// Return a grayscale version of this image.
654656
/// Returns `Luma` images in most cases. However, for `f32` images,
655657
/// this will return a grayscale `Rgb/Rgba` image instead.
658+
#[must_use]
656659
pub fn grayscale(&self) -> DynamicImage {
657660
match *self {
658661
DynamicImage::ImageLuma8(ref p) => DynamicImage::ImageLuma8(p.clone()),
@@ -690,6 +693,7 @@ impl DynamicImage {
690693
/// Returns a new image. The image's aspect ratio is preserved.
691694
/// The image is scaled to the maximum possible size that fits
692695
/// within the bounds specified by `nwidth` and `nheight`.
696+
#[must_use]
693697
pub fn resize(&self, nwidth: u32, nheight: u32, filter: imageops::FilterType) -> DynamicImage {
694698
if (nwidth, nheight) == self.dimensions() {
695699
return self.clone();
@@ -703,6 +707,7 @@ impl DynamicImage {
703707
/// Resize this image using the specified filter algorithm.
704708
/// Returns a new image. Does not preserve aspect ratio.
705709
/// `nwidth` and `nheight` are the new image's dimensions
710+
#[must_use]
706711
pub fn resize_exact(
707712
&self,
708713
nwidth: u32,
@@ -720,6 +725,7 @@ impl DynamicImage {
720725
/// This method uses a fast integer algorithm where each source
721726
/// pixel contributes to exactly one target pixel.
722727
/// May give aliasing artifacts if new size is close to old size.
728+
#[must_use]
723729
pub fn thumbnail(&self, nwidth: u32, nheight: u32) -> DynamicImage {
724730
let (width2, height2) =
725731
resize_dimensions(self.width(), self.height(), nwidth, nheight, false);
@@ -732,6 +738,7 @@ impl DynamicImage {
732738
/// This method uses a fast integer algorithm where each source
733739
/// pixel contributes to exactly one target pixel.
734740
/// May give aliasing artifacts if new size is close to old size.
741+
#[must_use]
735742
pub fn thumbnail_exact(&self, nwidth: u32, nheight: u32) -> DynamicImage {
736743
dynamic_map!(*self, ref p => imageops::thumbnail(p, nwidth, nheight))
737744
}
@@ -742,6 +749,7 @@ impl DynamicImage {
742749
/// within the larger (relative to aspect ratio) of the bounds
743750
/// specified by `nwidth` and `nheight`, then cropped to
744751
/// fit within the other bound.
752+
#[must_use]
745753
pub fn resize_to_fill(
746754
&self,
747755
nwidth: u32,
@@ -765,6 +773,7 @@ impl DynamicImage {
765773

766774
/// Performs a Gaussian blur on this image.
767775
/// `sigma` is a measure of how much to blur by.
776+
#[must_use]
768777
pub fn blur(&self, sigma: f32) -> DynamicImage {
769778
dynamic_map!(*self, ref p => imageops::blur(p, sigma))
770779
}
@@ -774,11 +783,13 @@ impl DynamicImage {
774783
/// `threshold` is a control of how much to sharpen.
775784
///
776785
/// See <https://en.wikipedia.org/wiki/Unsharp_masking#Digital_unsharp_masking>
786+
#[must_use]
777787
pub fn unsharpen(&self, sigma: f32, threshold: i32) -> DynamicImage {
778788
dynamic_map!(*self, ref p => imageops::unsharpen(p, sigma, threshold))
779789
}
780790

781791
/// Filters this image with the specified 3x3 kernel.
792+
#[must_use]
782793
pub fn filter3x3(&self, kernel: &[f32]) -> DynamicImage {
783794
if kernel.len() != 9 {
784795
panic!("filter must be 3 x 3")
@@ -790,13 +801,15 @@ impl DynamicImage {
790801
/// Adjust the contrast of this image.
791802
/// `contrast` is the amount to adjust the contrast by.
792803
/// Negative values decrease the contrast and positive values increase the contrast.
804+
#[must_use]
793805
pub fn adjust_contrast(&self, c: f32) -> DynamicImage {
794806
dynamic_map!(*self, ref p => imageops::contrast(p, c))
795807
}
796808

797809
/// Brighten the pixels of this image.
798810
/// `value` is the amount to brighten each pixel by.
799811
/// Negative values decrease the brightness and positive values increase it.
812+
#[must_use]
800813
pub fn brighten(&self, value: i32) -> DynamicImage {
801814
dynamic_map!(*self, ref p => imageops::brighten(p, value))
802815
}
@@ -805,31 +818,37 @@ impl DynamicImage {
805818
/// `value` is the degrees to rotate each pixel by.
806819
/// 0 and 360 do nothing, the rest rotates by the given degree value.
807820
/// just like the css webkit filter hue-rotate(180)
821+
#[must_use]
808822
pub fn huerotate(&self, value: i32) -> DynamicImage {
809823
dynamic_map!(*self, ref p => imageops::huerotate(p, value))
810824
}
811825

812826
/// Flip this image vertically
827+
#[must_use]
813828
pub fn flipv(&self) -> DynamicImage {
814829
dynamic_map!(*self, ref p => imageops::flip_vertical(p))
815830
}
816831

817832
/// Flip this image horizontally
833+
#[must_use]
818834
pub fn fliph(&self) -> DynamicImage {
819835
dynamic_map!(*self, ref p => imageops::flip_horizontal(p))
820836
}
821837

822838
/// Rotate this image 90 degrees clockwise.
839+
#[must_use]
823840
pub fn rotate90(&self) -> DynamicImage {
824841
dynamic_map!(*self, ref p => imageops::rotate90(p))
825842
}
826843

827844
/// Rotate this image 180 degrees clockwise.
845+
#[must_use]
828846
pub fn rotate180(&self) -> DynamicImage {
829847
dynamic_map!(*self, ref p => imageops::rotate180(p))
830848
}
831849

832850
/// Rotate this image 270 degrees clockwise.
851+
#[must_use]
833852
pub fn rotate270(&self) -> DynamicImage {
834853
dynamic_map!(*self, ref p => imageops::rotate270(p))
835854
}

0 commit comments

Comments
 (0)