pub fn new<S0, S1>(name: S0, contents: S1) -> Self
    where
        S0: Into<Box<str>>,
        S1: Into<Box<str>>,
    {
        let name = name.into();
        let contents = contents.into();
        let mut segments = IndexArrayBuilder::new();
        let mut newlines = IndexArrayBuilder::new();

        for (idx, grapheme) in contents.grapheme_indices(true) {
            if grapheme == "\n" {
                newlines.push(segments.len());
            }
            segments.push(idx);
        }
        segments.push(contents.len());

        let segments = segments.into();
        let newlines = newlines.into();
        let inner = SourceInner { name, contents, segments, newlines };
        Self { inner: Arc::new(inner) }
    }
/// Creates a new source code object given its name and its contents.
///
/// Contents are rearranged as grapheme clusters.
Creates a new source code object given its name and its contents.
Contents are rearranged as grapheme clusters.
Creates a new source code object given its name and its contents . Contents are rearranged as grapheme clusters .
pub fn new<S0, S1>(name: S0, contents: S1) -> Self
    where
        S0: Into<Box<str>>,
        S1: Into<Box<str>>,
    {
        let name = name.into();
        let contents = contents.into();
        let mut segments = IndexArrayBuilder::new();
        let mut newlines = IndexArrayBuilder::new();
        for (idx, grapheme) in contents.grapheme_indices(true) {
            if grapheme == "\n" {
                newlines.push(segments.len());
            }
            segments.push(idx);
        }
        segments.push(contents.len());
        let segments = segments.into();
        let newlines = newlines.into();
        let inner = SourceInner { name, contents, segments, newlines };
        Self { inner: Arc::new(inner) }
    }
pub fn new < S0 , S1 > ( name : S0 , contents : S1 ) -> Self where S0 : Into < Box < str > > , S1 : Into < Box < str > > , { let name = name . into ( ) ; let contents = contents . into ( ) ; let mut segments = IndexArrayBuilder :: new ( ) ; let mut newlines = IndexArrayBuilder :: new ( ) ; for ( idx , grapheme ) in contents . grapheme_indices ( true ) { if grapheme == " \n " { newlines . push ( segments . len ( ) ) ; } segments . push ( idx ) ; } segments . push ( contents . len ( ) ) ; let segments = segments . into ( ) ; let newlines = newlines . into ( ) ; let inner = SourceInner { name , contents , segments , newlines } ; Self { inner : Arc :: new ( inner ) } }
Creates a new source code object given its name and its contents.
Creates a new source code object given its name and its contents .
name
S0
contents
S1
name
S0
contents
S1