pub fn push_front(&mut self, entry: Entry<'a>) -> Result<(), HunkInsertionError> {
        let incoming_line_idx = entry.reference.start_position().row;

        // Add a new line vector if the entry has a greater line index, or if the vector is empty.
        // We ensure that the last line has the same line index as the incoming entry.
        if let Some(first_line) = self.0.front() {
            let first_line_idx = first_line.line_index;

            if incoming_line_idx > first_line_idx {
                return Err(HunkInsertionError::LaterLine {
                    incoming_line: incoming_line_idx,
                    first_line: first_line_idx,
                });
            }

            if first_line_idx - incoming_line_idx > 1 {
                return Err(HunkInsertionError::NonAdjacentHunk {
                    incoming_line: incoming_line_idx,
                    last_line: first_line_idx,
                });
            }

            // Only add a new line here if the the incoming line index is one after the last entry
            // If this isn't the case, the incoming line index must be the same as the last line
            // index, so we don't have to add a new line.
            if first_line_idx - incoming_line_idx == 1 {
                self.0.push_front(Line::new(incoming_line_idx));
            }
        } else {
            // line is empty
            self.0.push_front(Line::new(incoming_line_idx));
        }

        // Add the entry to the last line
        let first_line = self.0.front_mut().unwrap();

        // Entries must be added in order, so ensure the last entry in the line has an ending
        // column less than the incoming entry's starting column.
        // TODO(afnan) should this actually be checking the first entry?
        if let Some(&first_entry) = first_line.entries.back() {
            //if let Some(&first_entry) = first_line.entries.front() {
            // TODO(afnan) ^ this instead?
            // TODO(afnan) should this be start_position() instead of end?
            let first_col = first_entry.reference.end_position().column;
            //let first_col = first_entry.reference.start_position().column;
            // TODO(afnan) ^ this instead?
            let incoming_col = entry.reference.end_position().column;

            if incoming_col > first_col {
                return Err(HunkInsertionError::LaterColumn {
                    incoming_col,
                    first_col,
                });
            }
        }
        first_line.entries.push_front(entry);
        Ok(())
    }
/// Prepend an [entry](Entry) to a hunk
///
/// Entries can only be prepended in descending order (from last to first)
Prepend an [entry](Entry) to a hunk
Entries can only be prepended in descending order (from last to first)
Prepend an [ entry ] ( Entry ) to a hunk Entries can only be prepended in descending order ( from last to first )
pub fn push_front(&mut self, entry: Entry<'a>) -> Result<(), HunkInsertionError> {
        let incoming_line_idx = entry.reference.start_position().row;
        // Add a new line vector if the entry has a greater line index, or if the vector is empty.
        // We ensure that the last line has the same line index as the incoming entry.
        if let Some(first_line) = self.0.front() {
            let first_line_idx = first_line.line_index;
            if incoming_line_idx > first_line_idx {
                return Err(HunkInsertionError::LaterLine {
                    incoming_line: incoming_line_idx,
                    first_line: first_line_idx,
                });
            }
            if first_line_idx - incoming_line_idx > 1 {
                return Err(HunkInsertionError::NonAdjacentHunk {
                    incoming_line: incoming_line_idx,
                    last_line: first_line_idx,
                });
            }
            // Only add a new line here if the the incoming line index is one after the last entry
            // If this isn't the case, the incoming line index must be the same as the last line
            // index, so we don't have to add a new line.
            if first_line_idx - incoming_line_idx == 1 {
                self.0.push_front(Line::new(incoming_line_idx));
            }
        } else {
            // line is empty
            self.0.push_front(Line::new(incoming_line_idx));
        }
        // Add the entry to the last line
        let first_line = self.0.front_mut().unwrap();
        // Entries must be added in order, so ensure the last entry in the line has an ending
        // column less than the incoming entry's starting column.
        // TODO(afnan) should this actually be checking the first entry?
        if let Some(&first_entry) = first_line.entries.back() {
            //if let Some(&first_entry) = first_line.entries.front() {
            // TODO(afnan) ^ this instead?
            // TODO(afnan) should this be start_position() instead of end?
            let first_col = first_entry.reference.end_position().column;
            //let first_col = first_entry.reference.start_position().column;
            // TODO(afnan) ^ this instead?
            let incoming_col = entry.reference.end_position().column;
            if incoming_col > first_col {
                return Err(HunkInsertionError::LaterColumn {
                    incoming_col,
                    first_col,
                });
            }
        }
        first_line.entries.push_front(entry);
        Ok(())
    }
pub fn push_front ( & mut self , entry : Entry < ' a > ) -> Result < ( ) , HunkInsertionError > { let incoming_line_idx = entry . reference . start_position ( ) . row ; // Add a new line vector if the entry has a greater line index, or if the vector is empty. // We ensure that the last line has the same line index as the incoming entry. if let Some ( first_line ) = self . 0 . front ( ) { let first_line_idx = first_line . line_index ; if incoming_line_idx > first_line_idx { return Err ( HunkInsertionError :: LaterLine { incoming_line : incoming_line_idx , first_line : first_line_idx , } ) ; } if first_line_idx - incoming_line_idx > 1 { return Err ( HunkInsertionError :: NonAdjacentHunk { incoming_line : incoming_line_idx , last_line : first_line_idx , } ) ; } // Only add a new line here if the the incoming line index is one after the last entry // If this isn't the case, the incoming line index must be the same as the last line // index, so we don't have to add a new line. if first_line_idx - incoming_line_idx == 1 { self . 0 . push_front ( Line :: new ( incoming_line_idx ) ) ; } } else { // line is empty self . 0 . push_front ( Line :: new ( incoming_line_idx ) ) ; } // Add the entry to the last line let first_line = self . 0 . front_mut ( ) . unwrap ( ) ; // Entries must be added in order, so ensure the last entry in the line has an ending // column less than the incoming entry's starting column. // TODO(afnan) should this actually be checking the first entry? if let Some ( & first_entry ) = first_line . entries . back ( ) { //if let Some(&first_entry) = first_line.entries.front() { // TODO(afnan) ^ this instead? // TODO(afnan) should this be start_position() instead of end? let first_col = first_entry . reference . end_position ( ) . column ; //let first_col = first_entry.reference.start_position().column; // TODO(afnan) ^ this instead? let incoming_col = entry . reference . end_position ( ) . column ; if incoming_col > first_col { return Err ( HunkInsertionError :: LaterColumn { incoming_col , first_col , } ) ; } } first_line . entries . push_front ( entry ) ; Ok ( ( ) ) }
Prepend an [entry](Entry) to a hunk
Entries can only be prepended in descending order (from last to first)
Prepend an [ entry ] ( Entry ) to a hunk Entries can only be prepended in descending order ( from last to first )
&mut self
entry
Entry<'a>
&mut self
entry
Entry<'a>