Skip to main content

DiffOptionsBuilder

Struct DiffOptionsBuilder 

Source
pub struct DiffOptionsBuilder<M> { /* private fields */ }
Expand description

Builder for DiffOptions, shared by commands such as p4 diff, p4 diff2, p4 describe, and p4 annotate.

The mode type parameter tracks at compile time which kind of options are being assembled. The format constructors (DiffOptionsBuilder::context, DiffOptionsBuilder::rcs, DiffOptionsBuilder::summary, DiffOptionsBuilder::unified, and DiffOptionsBuilder::new) produce the DiffOptionsTypedMode state, where the whitespace builders (DiffOptionsBuilder::ignore_line_endings, DiffOptionsBuilder::ignore_changes_within_whitespace, DiffOptionsBuilder::ignore_all_whitespace) become available; DiffOptionsBuilder::raw produces the DiffOptionsRawMode state, which offers no further options — the two states never mix.

Both states convert into DiffOptions via From, so command methods that accept impl Into<DiffOptions> take a builder directly.

§Examples

use perforce_cli::cmd::DiffOptionsBuilder;

// `-dub`: unified format, ignore changes within whitespace
let builder =
    DiffOptionsBuilder::unified(None).ignore_changes_within_whitespace();

// `-dc3`: context format with 3 lines of context
let builder = DiffOptionsBuilder::context(Some(3));

// `-d-C 25`: pass `-C 25` straight to an external diff program
let builder = DiffOptionsBuilder::raw("-C 25");

Implementations§

Source§

impl DiffOptionsBuilder<DiffOptionsTypedMode>

Source

pub fn new() -> Self

Creates a new builder in the DiffOptionsTypedMode state with the default format and no whitespace handling; the resulting DiffOptions emits no -d flag.

Source

pub fn context(num: Option<u32>) -> Self

-dc[num]: context output format with num lines of context.

Source

pub fn rcs() -> Self

-dn: RCS output format.

Source

pub fn summary() -> Self

-ds: summary output format.

Source

pub fn unified(num: Option<u32>) -> Self

-du[num]: unified output format with num lines of context.

Examples found in repository?
examples/diff.rs (line 38)
27fn main() -> std::io::Result<()> {
28    let p4 = P4Cli::default();
29
30    // Workspace mode: force a diff against head, use the unified format with
31    // whitespace-insensitive comparison, and limit output to the first 10
32    // files. `force(true)` transitions the command into `WorkspaceMode`, and
33    // `limit(10)` further transitions it into `WorkspaceRegularMode` (where
34    // `-soptions` is unavailable).
35    let mut diff = p4
36        .diff()
37        .force(true)
38        .diff_options(DiffOptionsBuilder::unified(None).ignore_all_whitespace())
39        .limit(10);
40
41    let files = [OsStr::new("//depot/project/src/...")];
42    let output = diff.output_with(&files)?;
43    println!("{}", String::from_utf8_lossy(&output.stdout));
44
45    // Display mode: instead of full diffs, list only the unopened files that
46    // differ from the depot. `display_options` transitions `WorkspaceMode`
47    // into `WorkspaceDisplayMode`, where `-m max` is unavailable.
48    let mut list_changed = p4
49        .diff()
50        .force(true)
51        .display_options(DisplayOptions::UnopenedChanged);
52
53    let output = list_changed.output_with(&files)?;
54    println!("{}", String::from_utf8_lossy(&output.stdout));
55
56    // Stream-spec mode: diff a privately edited stream spec against the head
57    // version of another stream. `stream_spec_mode` transitions the command
58    // into `StreamSpecMode`; the stream spec is passed to `spawn_with`.
59    let mut stream_diff = p4.diff().stream_spec_mode();
60    let mut child = stream_diff.spawn_with(Some("//streams/main@head"))?;
61    child.wait()?;
62
63    Ok(())
64}
Source

pub fn ignore_line_endings(self) -> Self

-dl: ignore line-ending (CR/LF) convention when finding diffs.

Source

pub fn ignore_changes_within_whitespace(self) -> Self

-db: ignore changes made within whitespace (implies -dl).

Source

pub fn ignore_all_whitespace(self) -> Self

-dw: ignore whitespace altogether (implies -dl).

Examples found in repository?
examples/diff.rs (line 38)
27fn main() -> std::io::Result<()> {
28    let p4 = P4Cli::default();
29
30    // Workspace mode: force a diff against head, use the unified format with
31    // whitespace-insensitive comparison, and limit output to the first 10
32    // files. `force(true)` transitions the command into `WorkspaceMode`, and
33    // `limit(10)` further transitions it into `WorkspaceRegularMode` (where
34    // `-soptions` is unavailable).
35    let mut diff = p4
36        .diff()
37        .force(true)
38        .diff_options(DiffOptionsBuilder::unified(None).ignore_all_whitespace())
39        .limit(10);
40
41    let files = [OsStr::new("//depot/project/src/...")];
42    let output = diff.output_with(&files)?;
43    println!("{}", String::from_utf8_lossy(&output.stdout));
44
45    // Display mode: instead of full diffs, list only the unopened files that
46    // differ from the depot. `display_options` transitions `WorkspaceMode`
47    // into `WorkspaceDisplayMode`, where `-m max` is unavailable.
48    let mut list_changed = p4
49        .diff()
50        .force(true)
51        .display_options(DisplayOptions::UnopenedChanged);
52
53    let output = list_changed.output_with(&files)?;
54    println!("{}", String::from_utf8_lossy(&output.stdout));
55
56    // Stream-spec mode: diff a privately edited stream spec against the head
57    // version of another stream. `stream_spec_mode` transitions the command
58    // into `StreamSpecMode`; the stream spec is passed to `spawn_with`.
59    let mut stream_diff = p4.diff().stream_spec_mode();
60    let mut child = stream_diff.spawn_with(Some("//streams/main@head"))?;
61    child.wait()?;
62
63    Ok(())
64}
Source§

impl DiffOptionsBuilder<DiffOptionsRawMode>

Source

pub fn raw(s: impl Into<String>) -> Self

Passes an arbitrary option string directly to the underlying diff routine (for use with an external diff program).

The string is appended to -d verbatim. For example, DiffOptionsBuilder::raw("-C 25") produces -d-C 25.

Trait Implementations§

Source§

impl<M: Clone> Clone for DiffOptionsBuilder<M>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<M: Copy> Copy for DiffOptionsBuilder<M>

Source§

impl<M: Debug> Debug for DiffOptionsBuilder<M>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<M: Default> Default for DiffOptionsBuilder<M>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<M: Eq> Eq for DiffOptionsBuilder<M>

Source§

impl From<DiffOptionsBuilder<DiffOptionsRawMode>> for DiffOptions

Source§

fn from(builder: DiffOptionsBuilder<DiffOptionsRawMode>) -> Self

Converts to this type from the input type.
Source§

impl From<DiffOptionsBuilder<DiffOptionsTypedMode>> for DiffOptions

Source§

fn from(builder: DiffOptionsBuilder<DiffOptionsTypedMode>) -> Self

Converts to this type from the input type.
Source§

impl<M: PartialEq> PartialEq for DiffOptionsBuilder<M>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<M: PartialEq> StructuralPartialEq for DiffOptionsBuilder<M>

Auto Trait Implementations§

§

impl<M> Freeze for DiffOptionsBuilder<M>
where M: Freeze,

§

impl<M> RefUnwindSafe for DiffOptionsBuilder<M>
where M: RefUnwindSafe,

§

impl<M> Send for DiffOptionsBuilder<M>
where M: Send,

§

impl<M> Sync for DiffOptionsBuilder<M>
where M: Sync,

§

impl<M> Unpin for DiffOptionsBuilder<M>
where M: Unpin,

§

impl<M> UnsafeUnpin for DiffOptionsBuilder<M>
where M: UnsafeUnpin,

§

impl<M> UnwindSafe for DiffOptionsBuilder<M>
where M: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.