off64 0.9.0

Read from and write to byte slices with u64 offsets
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use num::Num;
use std::ops::Bound;
use std::ops::RangeBounds;

pub fn range_to_offset_and_len<N: Num + Copy, R: RangeBounds<N>>(range: R, total_len: N) -> (N, N) {
  let start = match range.start_bound() {
    Bound::Included(&n) => n,
    Bound::Excluded(&n) => n + N::one(),
    Bound::Unbounded => N::zero(),
  };
  let end = match range.end_bound() {
    Bound::Included(&n) => n + N::one(),
    Bound::Excluded(&n) => n,
    Bound::Unbounded => total_len,
  };
  (start, end - start)
}