Function textspan::lift_span_index[][src]

pub fn lift_span_index(
    span: Span,
    target_spans: &[Span]
) -> (Result<usize, usize>, Result<usize, usize>)

Convert span indices to target_spans based indices. Expects target_spans is sorted and not overlapping.

Example

use textspan::lift_span_index;
let target_spans = [(0, 3), (3, 4), (4, 9), (9, 12)];
assert_eq!(lift_span_index((0, 3), &target_spans), (Ok(0), Ok(1)));
assert_eq!(lift_span_index((0, 4), &target_spans), (Ok(0), Ok(2)));
assert_eq!(lift_span_index((1, 4), &target_spans), (Err(0), Ok(2)));
assert_eq!(lift_span_index((1, 5), &target_spans), (Err(0), Err(3)));
assert_eq!(lift_span_index((1, 9), &target_spans), (Err(0), Ok(3)));
assert_eq!(lift_span_index((0, 9), &target_spans), (Ok(0), Ok(3)));
assert_eq!(lift_span_index((1, 13), &target_spans), (Err(0), Err(4)));

let target_spans = [(3, 4), (4, 9), (9, 12)];
assert_eq!(lift_span_index((0, 9), &target_spans), (Err(0), Ok(2)));

assert_eq!(lift_span_index((0, 0), &[(0, 0)]), (Ok(0), Ok(1)));
assert_eq!(lift_span_index((0, 0), &[]), (Err(0), Err(0)));