Function source_chars

Source
pub fn source_chars<'a>(
    s: &'a str,
    code: &'a Rc<Code>,
    index_offset: usize,
) -> impl Iterator<Item = SourceChar> + 'a
Expand description

Creates an iterator of source chars from a string.

index_offset will be the index of the first source char’s location. For each succeeding char, the index will be incremented by one.

let s = "abc";
let code = Rc::new(Code {
    value: RefCell::new(s.to_string()),
    start_line_number: NonZeroU64::new(1).unwrap(),
    source: Rc::new(Source::Unknown),
});
let chars: Vec<_> = source_chars(s, &code, 10).collect();
assert_eq!(chars[0].value, 'a');
assert_eq!(chars[0].location.code, code);
assert_eq!(chars[0].location.range, 10..11);
assert_eq!(chars[1].value, 'b');
assert_eq!(chars[1].location.code, code);
assert_eq!(chars[1].location.range, 11..12);