Creates a new `HostAlignedByteCount`, rounding up to the nearest page. Returns an error if `bytes + page_size - 1` overflows.
(bytes: usize)
| 46 | /// |
| 47 | /// Returns an error if `bytes + page_size - 1` overflows. |
| 48 | pub fn new_rounded_up(bytes: usize) -> Result<Self, ByteCountOutOfBounds> { |
| 49 | let page_size = host_page_size(); |
| 50 | debug_assert!(page_size.is_power_of_two()); |
| 51 | match bytes.checked_add(page_size - 1) { |
| 52 | Some(v) => Ok(Self(v & !(page_size - 1))), |
| 53 | None => Err(ByteCountOutOfBounds(ByteCountOutOfBoundsKind::RoundUp)), |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | /// Creates a new `HostAlignedByteCount` from a `u64`, rounding up to the nearest page. |
| 58 | /// |
nothing calls this directly
no test coverage detected