diff --git a/src/lib.rs b/src/lib.rs index bc967fba..20747d08 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,7 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![cfg_attr(feature = "unstable", feature(asm, repr_simd, test))] +#![cfg_attr(feature = "unstable", feature(asm, repr_simd, test, fn_must_use))] //! A collection of strongly typed math tools for computer graphics with an inclination //! towards 2d graphics and layout. @@ -132,4 +132,3 @@ pub type Matrix4D = Transform3D; /// Temporary alias to facilitate the transition to the new naming scheme #[deprecated] pub type TypedMatrix4D = TypedTransform3D; - diff --git a/src/point.rs b/src/point.rs index c51b3caa..3121d23c 100644 --- a/src/point.rs +++ b/src/point.rs @@ -239,7 +239,7 @@ impl TypedPoint2D { /// This behavior is preserved for negative values (unlike the basic cast). /// For example `{ -0.1, -0.8 }.round() == { 0.0, -1.0 }`. #[inline] - #[must_use] + #[cfg_attr(feature = "unstable", must_use)] pub fn round(&self) -> Self { point2(self.x.round(), self.y.round()) } @@ -251,7 +251,7 @@ impl TypedPoint2D { /// This behavior is preserved for negative values (unlike the basic cast). /// For example `{ -0.1, -0.8 }.ceil() == { 0.0, 0.0 }`. #[inline] - #[must_use] + #[cfg_attr(feature = "unstable", must_use)] pub fn ceil(&self) -> Self { point2(self.x.ceil(), self.y.ceil()) } @@ -263,7 +263,7 @@ impl TypedPoint2D { /// This behavior is preserved for negative values (unlike the basic cast). /// For example `{ -0.1, -0.8 }.floor() == { -1.0, -1.0 }`. #[inline] - #[must_use] + #[cfg_attr(feature = "unstable", must_use)] pub fn floor(&self) -> Self { point2(self.x.floor(), self.y.floor()) } @@ -568,7 +568,7 @@ impl TypedPoint3D { /// /// This behavior is preserved for negative values (unlike the basic cast). #[inline] - #[must_use] + #[cfg_attr(feature = "unstable", must_use)] pub fn round(&self) -> Self { point3(self.x.round(), self.y.round(), self.z.round()) } @@ -579,7 +579,7 @@ impl TypedPoint3D { /// /// This behavior is preserved for negative values (unlike the basic cast). #[inline] - #[must_use] + #[cfg_attr(feature = "unstable", must_use)] pub fn ceil(&self) -> Self { point3(self.x.ceil(), self.y.ceil(), self.z.ceil()) } @@ -590,7 +590,7 @@ impl TypedPoint3D { /// /// This behavior is preserved for negative values (unlike the basic cast). #[inline] - #[must_use] + #[cfg_attr(feature = "unstable", must_use)] pub fn floor(&self) -> Self { point3(self.x.floor(), self.y.floor(), self.z.floor()) } diff --git a/src/rect.rs b/src/rect.rs index ce472fe4..02caeda3 100644 --- a/src/rect.rs +++ b/src/rect.rs @@ -167,7 +167,7 @@ where T: Copy + Clone + Zero + PartialOrd + PartialEq + Add + Sub) -> Self { Self::new(self.origin + *by, self.size) } @@ -192,7 +192,7 @@ where T: Copy + Clone + Zero + PartialOrd + PartialEq + Add + Sub Self { TypedRect::new( TypedPoint2D::new(self.origin.x - width, self.origin.y - height), @@ -201,7 +201,7 @@ where T: Copy + Clone + Zero + PartialOrd + PartialEq + Add + Sub, height: Length) -> Self { self.inflate(width.get(), height.get()) } @@ -222,7 +222,7 @@ where T: Copy + Clone + Zero + PartialOrd + PartialEq + Add + Sub) -> Self { self.translate(&size.to_vector()) } @@ -394,7 +394,7 @@ impl + Sub, U> TypedRect /// avoid pixel rounding errors. /// Note that this is *not* rounding to nearest integer if the values are negative. /// They are always rounding as floor(n + 0.5). - #[must_use] + #[cfg_attr(feature = "unstable", must_use)] pub fn round(&self) -> Self { let origin = self.origin.round(); let size = self.origin.add_size(&self.size).round() - origin; @@ -403,7 +403,7 @@ impl + Sub, U> TypedRect /// Return a rectangle with edges rounded to integer coordinates, such that /// the original rectangle contains the resulting rectangle. - #[must_use] + #[cfg_attr(feature = "unstable", must_use)] pub fn round_in(&self) -> Self { let origin = self.origin.ceil(); let size = self.origin.add_size(&self.size).floor() - origin; @@ -412,7 +412,7 @@ impl + Sub, U> TypedRect /// Return a rectangle with edges rounded to integer coordinates, such that /// the original rectangle is contained in the resulting rectangle. - #[must_use] + #[cfg_attr(feature = "unstable", must_use)] pub fn round_out(&self) -> Self { let origin = self.origin.floor(); let size = self.origin.add_size(&self.size).ceil() - origin; diff --git a/src/transform2d.rs b/src/transform2d.rs index c9637623..2c28cf11 100644 --- a/src/transform2d.rs +++ b/src/transform2d.rs @@ -161,7 +161,7 @@ where T: Copy + Clone + /// Returns the multiplication of the two matrices such that mat's transformation /// applies after self's transformation. - #[must_use] + #[cfg_attr(feature = "unstable", must_use)] pub fn post_mul(&self, mat: &TypedTransform2D) -> TypedTransform2D { TypedTransform2D::row_major( self.m11 * mat.m11 + self.m12 * mat.m21, @@ -175,7 +175,7 @@ where T: Copy + Clone + /// Returns the multiplication of the two matrices such that mat's transformation /// applies before self's transformation. - #[must_use] + #[cfg_attr(feature = "unstable", must_use)] pub fn pre_mul(&self, mat: &TypedTransform2D) -> TypedTransform2D { mat.post_mul(self) } @@ -191,13 +191,13 @@ where T: Copy + Clone + } /// Applies a translation after self's transformation and returns the resulting transform. - #[must_use] + #[cfg_attr(feature = "unstable", must_use)] pub fn post_translate(&self, v: TypedVector2D) -> Self { self.post_mul(&TypedTransform2D::create_translation(v.x, v.y)) } /// Applies a translation before self's transformation and returns the resulting transform. - #[must_use] + #[cfg_attr(feature = "unstable", must_use)] pub fn pre_translate(&self, v: TypedVector2D) -> Self { self.pre_mul(&TypedTransform2D::create_translation(v.x, v.y)) } @@ -213,13 +213,13 @@ where T: Copy + Clone + } /// Applies a scale after self's transformation and returns the resulting transform. - #[must_use] + #[cfg_attr(feature = "unstable", must_use)] pub fn post_scale(&self, x: T, y: T) -> Self { self.post_mul(&TypedTransform2D::create_scale(x, y)) } /// Applies a scale before self's transformation and returns the resulting transform. - #[must_use] + #[cfg_attr(feature = "unstable", must_use)] pub fn pre_scale(&self, x: T, y: T) -> Self { TypedTransform2D::row_major( self.m11 * x, self.m12, @@ -241,20 +241,20 @@ where T: Copy + Clone + } /// Applies a rotation after self's transformation and returns the resulting transform. - #[must_use] + #[cfg_attr(feature = "unstable", must_use)] pub fn post_rotate(&self, theta: Radians) -> Self { self.post_mul(&TypedTransform2D::create_rotation(theta)) } /// Applies a rotation after self's transformation and returns the resulting transform. - #[must_use] + #[cfg_attr(feature = "unstable", must_use)] pub fn pre_rotate(&self, theta: Radians) -> Self { self.pre_mul(&TypedTransform2D::create_rotation(theta)) } /// Returns the given point transformed by this transform. #[inline] - #[must_use] + #[cfg_attr(feature = "unstable", must_use)] pub fn transform_point(&self, point: &TypedPoint2D) -> TypedPoint2D { TypedPoint2D::new(point.x * self.m11 + point.y * self.m21 + self.m31, point.x * self.m12 + point.y * self.m22 + self.m32) @@ -262,7 +262,7 @@ where T: Copy + Clone + /// Returns the given vector transformed by this matrix. #[inline] - #[must_use] + #[cfg_attr(feature = "unstable", must_use)] pub fn transform_vector(&self, vec: &TypedVector2D) -> TypedVector2D { vec2(vec.x * self.m11 + vec.y * self.m21, vec.x * self.m12 + vec.y * self.m22) @@ -271,7 +271,7 @@ where T: Copy + Clone + /// Returns a rectangle that encompasses the result of transforming the given rectangle by this /// transform. #[inline] - #[must_use] + #[cfg_attr(feature = "unstable", must_use)] pub fn transform_rect(&self, rect: &TypedRect) -> TypedRect { TypedRect::from_points(&[ self.transform_point(&rect.origin), @@ -287,7 +287,7 @@ where T: Copy + Clone + } /// Returns the inverse transform if possible. - #[must_use] + #[cfg_attr(feature = "unstable", must_use)] pub fn inverse(&self) -> Option> { let det = self.determinant(); diff --git a/src/transform3d.rs b/src/transform3d.rs index 7f33be67..42184d4e 100644 --- a/src/transform3d.rs +++ b/src/transform3d.rs @@ -382,7 +382,7 @@ where T: Copy + Clone + } /// Multiplies all of the transform's component by a scalar and returns the result. - #[must_use] + #[cfg_attr(feature = "unstable", must_use)] pub fn mul_s(&self, x: T) -> Self { TypedTransform3D::row_major( self.m11 * x, self.m12 * x, self.m13 * x, self.m14 * x, @@ -469,13 +469,13 @@ where T: Copy + Clone + } /// Returns a transform with a translation applied before self's transformation. - #[must_use] + #[cfg_attr(feature = "unstable", must_use)] pub fn pre_translate(&self, v: TypedVector3D) -> Self { self.pre_mul(&TypedTransform3D::create_translation(v.x, v.y, v.z)) } /// Returns a transform with a translation applied after self's transformation. - #[must_use] + #[cfg_attr(feature = "unstable", must_use)] pub fn post_translate(&self, v: TypedVector3D) -> Self { self.post_mul(&TypedTransform3D::create_translation(v.x, v.y, v.z)) } @@ -492,7 +492,7 @@ where T: Copy + Clone + } /// Returns a transform with a scale applied before self's transformation. - #[must_use] + #[cfg_attr(feature = "unstable", must_use)] pub fn pre_scale(&self, x: T, y: T, z: T) -> Self { TypedTransform3D::row_major( self.m11 * x, self.m12, self.m13, self.m14, @@ -503,7 +503,7 @@ where T: Copy + Clone + } /// Returns a transform with a scale applied after self's transformation. - #[must_use] + #[cfg_attr(feature = "unstable", must_use)] pub fn post_scale(&self, x: T, y: T, z: T) -> Self { self.post_mul(&TypedTransform3D::create_scale(x, y, z)) } @@ -546,13 +546,13 @@ where T: Copy + Clone + } /// Returns a transform with a rotation applied after self's transformation. - #[must_use] + #[cfg_attr(feature = "unstable", must_use)] pub fn post_rotate(&self, x: T, y: T, z: T, theta: Radians) -> Self { self.post_mul(&TypedTransform3D::create_rotation(x, y, z, theta)) } /// Returns a transform with a rotation applied before self's transformation. - #[must_use] + #[cfg_attr(feature = "unstable", must_use)] pub fn pre_rotate(&self, x: T, y: T, z: T, theta: Radians) -> Self { self.pre_mul(&TypedTransform3D::create_rotation(x, y, z, theta)) } diff --git a/src/vector.rs b/src/vector.rs index 05296f64..0fa3f087 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -272,7 +272,7 @@ impl TypedVector2D { /// This behavior is preserved for negative values (unlike the basic cast). /// For example `{ -0.1, -0.8 }.round() == { 0.0, -1.0 }`. #[inline] - #[must_use] + #[cfg_attr(feature = "unstable", must_use)] pub fn round(&self) -> Self { vec2(self.x.round(), self.y.round()) } @@ -284,7 +284,7 @@ impl TypedVector2D { /// This behavior is preserved for negative values (unlike the basic cast). /// For example `{ -0.1, -0.8 }.ceil() == { 0.0, 0.0 }`. #[inline] - #[must_use] + #[cfg_attr(feature = "unstable", must_use)] pub fn ceil(&self) -> Self { vec2(self.x.ceil(), self.y.ceil()) } @@ -296,7 +296,7 @@ impl TypedVector2D { /// This behavior is preserved for negative values (unlike the basic cast). /// For example `{ -0.1, -0.8 }.floor() == { -1.0, -1.0 }`. #[inline] - #[must_use] + #[cfg_attr(feature = "unstable", must_use)] pub fn floor(&self) -> Self { vec2(self.x.floor(), self.y.floor()) } @@ -637,7 +637,7 @@ impl TypedVector3D { /// /// This behavior is preserved for negative values (unlike the basic cast). #[inline] - #[must_use] + #[cfg_attr(feature = "unstable", must_use)] pub fn round(&self) -> Self { vec3(self.x.round(), self.y.round(), self.z.round()) } @@ -648,7 +648,7 @@ impl TypedVector3D { /// /// This behavior is preserved for negative values (unlike the basic cast). #[inline] - #[must_use] + #[cfg_attr(feature = "unstable", must_use)] pub fn ceil(&self) -> Self { vec3(self.x.ceil(), self.y.ceil(), self.z.ceil()) } @@ -659,7 +659,7 @@ impl TypedVector3D { /// /// This behavior is preserved for negative values (unlike the basic cast). #[inline] - #[must_use] + #[cfg_attr(feature = "unstable", must_use)] pub fn floor(&self) -> Self { vec3(self.x.floor(), self.y.floor(), self.z.floor()) }