pub fn new(filename: impl AsRef<str>, string: &'a str) -> Self {
        let linebreaks: Vec<_> = iter::once(0)
            .chain(
                string
                    .chars()
                    .enumerate()
                    .filter(|(_idx, c)| *c == '\n')
                    .map(|(idx, _c)| idx + 1),
            )
            .chain(iter::once(string.len()))
            .collect();
        let lines = linebreaks
            .windows(2)
            // Last line when there is a newline at the and of string
            .filter(|bounds| bounds[0] != bounds[1])
            .map(|bounds| AnnotatedLine {
                start: bounds[0],
                content: &string[bounds[0]..bounds[1]],
                annotations: vec![],
            })
            .collect();
        Self {
            filename: filename.as_ref().into(),
            lines,
        }
    }
/// Create an annotation list from string. `filename` is used only to format messages, so
/// corresponding file doesn't need to exist.
Create an annotation list from string. `filename` is used only to format messages, so
corresponding file doesn't need to exist.
Create an annotation list from string . ` filename ` is used only to format messages so corresponding file doesn ' t need to exist .
pub fn new(filename: impl AsRef<str>, string: &'a str) -> Self {
        let linebreaks: Vec<_> = iter::once(0)
            .chain(
                string
                    .chars()
                    .enumerate()
                    .filter(|(_idx, c)| *c == '\n')
                    .map(|(idx, _c)| idx + 1),
            )
            .chain(iter::once(string.len()))
            .collect();
        let lines = linebreaks
            .windows(2)
            // Last line when there is a newline at the and of string
            .filter(|bounds| bounds[0] != bounds[1])
            .map(|bounds| AnnotatedLine {
                start: bounds[0],
                content: &string[bounds[0]..bounds[1]],
                annotations: vec![],
            })
            .collect();
        Self {
            filename: filename.as_ref().into(),
            lines,
        }
    }
pub fn new ( filename : impl AsRef < str > , string : & ' a str ) -> Self { let linebreaks : Vec < _ > = iter :: once ( 0 ) . chain ( string . chars ( ) . enumerate ( ) . filter ( | ( _idx , c ) | * c == '\n' ) . map ( | ( idx , _c ) | idx + 1 ) , ) . chain ( iter :: once ( string . len ( ) ) ) . collect ( ) ; let lines = linebreaks . windows ( 2 ) // Last line when there is a newline at the and of string . filter ( | bounds | bounds [ 0 ] != bounds [ 1 ] ) . map ( | bounds | AnnotatedLine { start : bounds [ 0 ] , content : & string [ bounds [ 0 ] .. bounds [ 1 ] ] , annotations : vec ! [ ] , } ) . collect ( ) ; Self { filename : filename . as_ref ( ) . into ( ) , lines , } }
Create an annotation list from string.
Create an annotation list from string .
filename
impl AsRef<str>
string
&'a str
filename
impl AsRef<str>
string
&'a str