nvim_api/
utils.rs

1use std::ops::{Bound, RangeBounds};
2
3use nvim_types::Integer;
4
5pub(crate) fn range_to_limits<R>(range: R) -> (Integer, Integer)
6where
7    R: RangeBounds<usize>,
8{
9    let start = match range.start_bound() {
10        Bound::Unbounded => 0,
11        Bound::Excluded(&n) => (n + 1) as Integer,
12        Bound::Included(&n) => n as Integer,
13    };
14
15    let end = match range.end_bound() {
16        // The Neovim API generally uses -1 to indicate "until the end".
17        Bound::Unbounded => -1,
18        Bound::Excluded(&n) => n.saturating_sub(1) as Integer,
19        Bound::Included(&n) => n as Integer,
20    };
21
22    (start, end)
23}