Skip to content

Commit

Permalink
Add max_assign() and min_assign() methods (#57)
Browse files Browse the repository at this point in the history
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
  • Loading branch information
mrobinson and Loirooriol committed May 17, 2024
1 parent 228cf8d commit d992002
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "app_units"
version = "0.7.5"
version = "0.7.6"
authors = ["The Servo Project Developers"]
description = "Servo app units type (Au)"
documentation = "https://docs.rs/app_units/"
Expand Down
48 changes: 48 additions & 0 deletions src/app_unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,16 @@ impl Au {
pub fn abs(self) -> Self {
Au(self.0.abs())
}

#[inline]
pub fn max_assign(&mut self, other: Self) {
*self = (*self).max(other);
}

#[inline]
pub fn min_assign(&mut self, other: Self) {
*self = (*self).min(other);
}
}

#[test]
Expand Down Expand Up @@ -399,6 +409,44 @@ fn convert() {
assert_eq!(Au::from_f64_px(6.13), Au(368));
}

#[test]
fn max_assign() {
let mut au = Au(5);
au.max_assign(Au(10));
assert_eq!(au, Au(10));

let mut au = Au(5);
au.max_assign(Au(-10));
assert_eq!(au, Au(5));

let mut au = Au(100);
au.max_assign(MAX_AU);
assert_eq!(au, MAX_AU);

let mut au = Au(-100);
au.max_assign(MAX_AU);
assert_eq!(au, MAX_AU);
}

#[test]
fn min_assign() {
let mut au = Au(5);
au.min_assign(Au(10));
assert_eq!(au, Au(5));

let mut au = Au(5);
au.min_assign(Au(-10));
assert_eq!(au, Au(-10));

let mut au = Au(100);
au.min_assign(MAX_AU);
assert_eq!(au, Au(100));

let mut au = Au(-100);
au.min_assign(MAX_AU);
assert_eq!(au, Au(-100));
}

#[cfg(feature = "serde_serialization")]
#[test]
fn serialize() {
Expand Down

0 comments on commit d992002

Please sign in to comment.