Skip to content

Commit

Permalink
Change use of usize::abs_diff due to MSRV
Browse files Browse the repository at this point in the history
  • Loading branch information
Eliasin committed Jul 7, 2022
1 parent e0cd60c commit 3dbefac
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,12 @@ fn allocation_size_overflow<T>() -> T {
panic!("requested allocation size overflowed")
}

// This can be migrated to directly use `usize::abs_diff` when the MSRV
// reaches `1.60`
fn abs_diff(a: usize, b: usize) -> usize {
usize::max(a, b) - usize::min(a, b)
}

impl Bump {
/// Construct a new arena to bump allocate into.
///
Expand Down Expand Up @@ -594,7 +600,7 @@ impl Bump {
if allocated_bytes > allocation_limit {
None
} else {
Some(allocation_limit.abs_diff(allocated_bytes))
Some(abs_diff(allocation_limit, allocated_bytes))
}
})
}
Expand Down

0 comments on commit 3dbefac

Please sign in to comment.