/// Add a file to the database, returning the handle that can be used to refer to it again.
Add a file to the database, returning the handle that can be used to refer to it again.
Add a file to the database returning the handle that can be used to refer to it again .
pub fn add(&mut self, name: impl Into<String>, contents: impl Into<String>) -> FileId {
        let file_id = FileId(self.files.len());
        let contents = contents.into();
        // Pre-compute the line starting positions
        let line_starts = std::iter::once(0)
            .chain(contents.match_indices('\n').map(|(i, _)| i + 1))
            .chain(std::iter::once(contents.len()))
            .map(ByteIndex::from)
            .collect();
        // Add the file to the database
        self.files.push(File {
            id: file_id,
            name: name.into(),
            contents,
            line_starts,
        });
        file_id
    }
pub fn add ( & mut self , name : impl Into < String > , contents : impl Into < String > ) -> FileId { let file_id = FileId ( self . files . len ( ) ) ; let contents = contents . into ( ) ; // Pre-compute the line starting positions let line_starts = std :: iter :: once ( 0 ) . chain ( contents . match_indices ( '\n' ) . map ( | ( i , _ ) | i + 1 ) ) . chain ( std :: iter :: once ( contents . len ( ) ) ) . map ( ByteIndex :: from ) . collect ( ) ; // Add the file to the database self . files . push ( File { id : file_id , name : name . into ( ) , contents , line_starts , } ) ; file_id }
Add a file to the database, returning the handle that can be used to refer to it again.
Add a file to the database returning the handle that can be used to refer to it again .
&mut self
name
impl Into<String>
contents
impl Into<String>