Trait ConsumeHunk

Source
pub trait ConsumeHunk {
    type Out;

    // Required methods
    fn consume_hunk(
        &mut self,
        before_hunk_start: u32,
        before_hunk_len: u32,
        after_hunk_start: u32,
        after_hunk_len: u32,
        header: &str,
        hunk: &[u8],
    ) -> Result<()>;
    fn finish(self) -> Self::Out;
}
Available on crate feature blob only.
Expand description

A utility trait for use in UnifiedDiff.

Required Associated Types§

Source

type Out

The item this instance produces after consuming all hunks.

Required Methods§

Source

fn consume_hunk( &mut self, before_hunk_start: u32, before_hunk_len: u32, after_hunk_start: u32, after_hunk_len: u32, header: &str, hunk: &[u8], ) -> Result<()>

Consume a single hunk in unified diff format, that would be prefixed with header. Note that all newlines are added.

Note that the UnifiedDiff sink will wrap its output in an std::io::Result. After this method returned its first error, it will not be called anymore.

The following is hunk-related information and the same that is used in the header.

  • before_hunk_start is the 1-based first line of this hunk in the old file.
  • before_hunk_len the amount of lines of this hunk in the old file.
  • after_hunk_start is the 1-based first line of this hunk in the new file.
  • after_hunk_len the amount of lines of this hunk in the new file.
Source

fn finish(self) -> Self::Out

Called after the last hunk is consumed to produce an output.

Implementations on Foreign Types§

Source§

impl ConsumeHunk for String

An implementation that fails if the input isn’t UTF-8.

Source§

type Out = String

Source§

fn consume_hunk( &mut self, _: u32, _: u32, _: u32, _: u32, header: &str, hunk: &[u8], ) -> Result<()>

Source§

fn finish(self) -> Self::Out

Source§

impl ConsumeHunk for Vec<u8>

An implementation that writes hunks into a byte buffer.

Source§

type Out = Vec<u8>

Source§

fn consume_hunk( &mut self, _: u32, _: u32, _: u32, _: u32, header: &str, hunk: &[u8], ) -> Result<()>

Source§

fn finish(self) -> Self::Out

Implementors§