`RangeBounds` usage / ergonomics

I was just attempting to use RangeBounds.

My aim is to provide an API akin to fn do_something(&self, range: R, ... ) where R: RangeBounds. This is a member function of a structure that internally holds some data in a VecDeque. The range is used to specify what sub-range of the data to operate on.

My problem is it’s very verbose to “unwrap” the RangeBounds contents, basically I have a code like this:

let from = match range.start_bound() {
    Included(b) => *b,
    Excluded(b) => *b + 1,
    Unbounded => 0,
};

let till = match range.start_bound() {
    Included(b) => length.min(*b + 1),
    Excluded(b) => length.min(*b),
    Unbounded => length,
};

It feels like this task should be easier. I’m really not sure I’m using RangeBounds right and whether I should even be using it in the first place. I’m also confused by the distinction between RangeBounds and SliceIndex.

How would that API be best created? Preferably on Rust stable…