Skip to content

Commit d992002

Browse files
Add max_assign() and min_assign() methods (#57)
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
1 parent 228cf8d commit d992002

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "app_units"
3-
version = "0.7.5"
3+
version = "0.7.6"
44
authors = ["The Servo Project Developers"]
55
description = "Servo app units type (Au)"
66
documentation = "https://docs.rs/app_units/"

src/app_unit.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,16 @@ impl Au {
277277
pub fn abs(self) -> Self {
278278
Au(self.0.abs())
279279
}
280+
281+
#[inline]
282+
pub fn max_assign(&mut self, other: Self) {
283+
*self = (*self).max(other);
284+
}
285+
286+
#[inline]
287+
pub fn min_assign(&mut self, other: Self) {
288+
*self = (*self).min(other);
289+
}
280290
}
281291

282292
#[test]
@@ -399,6 +409,44 @@ fn convert() {
399409
assert_eq!(Au::from_f64_px(6.13), Au(368));
400410
}
401411

412+
#[test]
413+
fn max_assign() {
414+
let mut au = Au(5);
415+
au.max_assign(Au(10));
416+
assert_eq!(au, Au(10));
417+
418+
let mut au = Au(5);
419+
au.max_assign(Au(-10));
420+
assert_eq!(au, Au(5));
421+
422+
let mut au = Au(100);
423+
au.max_assign(MAX_AU);
424+
assert_eq!(au, MAX_AU);
425+
426+
let mut au = Au(-100);
427+
au.max_assign(MAX_AU);
428+
assert_eq!(au, MAX_AU);
429+
}
430+
431+
#[test]
432+
fn min_assign() {
433+
let mut au = Au(5);
434+
au.min_assign(Au(10));
435+
assert_eq!(au, Au(5));
436+
437+
let mut au = Au(5);
438+
au.min_assign(Au(-10));
439+
assert_eq!(au, Au(-10));
440+
441+
let mut au = Au(100);
442+
au.min_assign(MAX_AU);
443+
assert_eq!(au, Au(100));
444+
445+
let mut au = Au(-100);
446+
au.min_assign(MAX_AU);
447+
assert_eq!(au, Au(-100));
448+
}
449+
402450
#[cfg(feature = "serde_serialization")]
403451
#[test]
404452
fn serialize() {

0 commit comments

Comments
 (0)