shift_range_in_content

Function shift_range_in_content 

Source
pub fn shift_range_in_content<T>(
    range: Range<T>,
    shift: Shift<T>,
    content: &str,
) -> Option<Range<T>>
where T: PrimInt,
Expand description

Creates a new range with the start and end values shifted by the given amount and checks that the range is valid in the given content. If new range falls outside of the given content, None will be returned.

ยงExample:

use query_range::{shift_range_in_content, Shift};

let test_str = "this is a test";

let range = 0..5;
assert_eq!(shift_range_in_content(range, Shift::Up(2), test_str), Some(2..7));

let range = 0..5;
assert_eq!(shift_range_in_content(range, Shift::Up(20), test_str), None);