fn new(src: &str, span: &Span) -> Self {
        debug_assert!(span.start < src.len());
        debug_assert!(span.end <= src.len());
        debug_assert!(span.start != span.end);

        let mut line = 1;
        let mut col = 1;
        let mut idx = 0;

        let mut ps = PosSpan {
            start_line: 0,
            start_col: 0,
            end_line: 0,
            end_col: 0,
        };

        for c in src.chars() {
            if idx == span.start {
                ps.start_line = line;
                ps.start_col = col;
            } else if idx == span.end {
                ps.end_line = line;
                ps.end_col = col;
            }

            if c == '\n' {
                line += 1;
                col = 0;
            }
            col += 1;
            idx += 1;
        }
        if ps.end_line == 0 {
            ps.end_line = line;
            ps.end_col = col;
        }

        debug_assert!(ps.start_line != 0);
        debug_assert!(ps.start_col != 0);
        debug_assert!(ps.end_line != 0);
        debug_assert!(ps.end_col != 0);
        ps
    }
/// Construct a positional span from a span and the source.
///
/// We take a complexity and speed hit here in order to make thinking
/// about spans easier for anyone who wants to construct an error.
/// Remake sources are small, so the perf hit is not bad, and it is
/// much easier to think about spans in terms of char offsets for the
/// parser and interpreter.
Construct a positional span from a span and the source.
We take a complexity and speed hit here in order to make thinking
about spans easier for anyone who wants to construct an error.
Remake sources are small, so the perf hit is not bad, and it is
much easier to think about spans in terms of char offsets for the
parser and interpreter.
Construct a positional span from a span and the source . We take a complexity and speed hit here in order to make thinking about spans easier for anyone who wants to construct an error . Remake sources are small so the perf hit is not bad and it is much easier to think about spans in terms of char offsets for the parser and interpreter .
fn new(src: &str, span: &Span) -> Self {
        debug_assert!(span.start < src.len());
        debug_assert!(span.end <= src.len());
        debug_assert!(span.start != span.end);
        let mut line = 1;
        let mut col = 1;
        let mut idx = 0;
        let mut ps = PosSpan {
            start_line: 0,
            start_col: 0,
            end_line: 0,
            end_col: 0,
        };
        for c in src.chars() {
            if idx == span.start {
                ps.start_line = line;
                ps.start_col = col;
            } else if idx == span.end {
                ps.end_line = line;
                ps.end_col = col;
            }
            if c == '\n' {
                line += 1;
                col = 0;
            }
            col += 1;
            idx += 1;
        }
        if ps.end_line == 0 {
            ps.end_line = line;
            ps.end_col = col;
        }
        debug_assert!(ps.start_line != 0);
        debug_assert!(ps.start_col != 0);
        debug_assert!(ps.end_line != 0);
        debug_assert!(ps.end_col != 0);
        ps
    }
fn new ( src : & str , span : & Span ) -> Self { debug_assert ! ( span start src len ( ) ) ; debug_assert ! ( span end src len ( ) ) ; debug_assert ! ( span start span end ) ; let mut line = 1 ; let mut col = 1 ; let mut idx = 0 ; let mut ps = PosSpan { start_line : 0 , start_col : 0 , end_line : 0 , end_col : 0 , } ; for c in src . chars ( ) { if idx == span . start { ps . start_line = line ; ps . start_col = col ; } else if idx == span . end { ps . end_line = line ; ps . end_col = col ; } if c == '\n' { line += 1 ; col = 0 ; } col += 1 ; idx += 1 ; } if ps . end_line == 0 { ps . end_line = line ; ps . end_col = col ; } debug_assert ! ( ps start_line 0 ) ; debug_assert ! ( ps start_col 0 ) ; debug_assert ! ( ps end_line 0 ) ; debug_assert ! ( ps end_col 0 ) ; ps }
Construct a positional span from a span and the source.
Construct a positional span from a span and the source .
src
&str
span
&Span