Skip to main content

ApplyOptions

Struct ApplyOptions 

Source
pub struct ApplyOptions {
    pub dry_run: bool,
    pub fuzz_factor: f32,
}
Expand description

Options for configuring how a patch is applied.

This struct controls the behavior of patch application functions like apply_patch_to_file() and apply_patch_to_content(). It allows you to enable dry-run mode, configure the fuzzy matching threshold, and more.

While you can construct it directly, it’s often more convenient to use one of the associated functions like ApplyOptions::new(), ApplyOptions::dry_run(), or the fluent with_dry_run() and with_fuzz_factor() methods.

§Example

use mpatch::ApplyOptions;

// Direct construction for full control.
let custom_options = ApplyOptions {
    dry_run: true,
    fuzz_factor: 0.9,
};

// Using a convenience constructor for common cases.
let dry_run_options = ApplyOptions::dry_run();
assert_eq!(dry_run_options.dry_run, true);

// Using fluent methods for a chainable style.
let fluent_options = ApplyOptions::new()
    .with_dry_run(true)
    .with_fuzz_factor(0.5);
assert_eq!(fluent_options.fuzz_factor, 0.5);

Fields§

§dry_run: bool

If true, no files will be modified. Instead, a diff of the proposed changes will be generated and returned in PatchResult.

This is the primary way to preview the outcome of a patch operation without making any changes to the filesystem. When dry_run is enabled, functions like apply_patch_to_file() will populate the diff field of the returned PatchResult.

§Example

// Create options for a dry run.
let options = ApplyOptions {
    dry_run: true,
    fuzz_factor: 0.7,
};

assert!(options.dry_run);
§fuzz_factor: f32

The similarity threshold for fuzzy matching (0.0 to 1.0). Higher is stricter. 0.0 disables fuzzy matching.

Implementations§

Source§

impl ApplyOptions

Source

pub fn new() -> Self

Creates a new ApplyOptions instance with default values.

This is an alias for ApplyOptions::default().

§Example
let options = ApplyOptions::new();
assert_eq!(options.dry_run, false);
assert_eq!(options.fuzz_factor, 0.7);
Source

pub fn dry_run() -> Self

Creates a new ApplyOptions instance configured for a dry run.

All other options are set to their default values.

§Example
let options = ApplyOptions::dry_run();
assert_eq!(options.dry_run, true);
assert_eq!(options.fuzz_factor, 0.7);
Source

pub fn exact() -> Self

Creates a new ApplyOptions instance configured for an exact match (fuzz factor 0.0).

All other options are set to their default values.

§Example
let options = ApplyOptions::exact();

assert_eq!(options.dry_run, false);
assert_eq!(options.fuzz_factor, 0.0);
Source

pub fn with_dry_run(self, dry_run: bool) -> Self

Returns a new ApplyOptions instance with the dry_run flag set.

This is a fluent method that allows for chaining.

§Example
let options = ApplyOptions::new().with_dry_run(true);
assert_eq!(options.dry_run, true);

let options2 = options.with_dry_run(false);
assert_eq!(options2.dry_run, false);
Source

pub fn with_fuzz_factor(self, fuzz_factor: f32) -> Self

Returns a new ApplyOptions instance with the fuzz_factor set.

This is a fluent method that allows for chaining.

§Example
let options = ApplyOptions::new().with_fuzz_factor(0.9);
assert_eq!(options.fuzz_factor, 0.9);

let options2 = options.with_fuzz_factor(0.5);
assert_eq!(options2.fuzz_factor, 0.5);
Source

pub fn builder() -> ApplyOptionsBuilder

Creates a new builder for ApplyOptions.

This provides a classic builder pattern for constructing an ApplyOptions struct, which can be useful when the configuration is built conditionally or comes from multiple sources.

§Example
let options = ApplyOptions::builder()
    .dry_run(true)
    .fuzz_factor(0.8)
    .build();

assert_eq!(options.dry_run, true);
assert_eq!(options.fuzz_factor, 0.8);

Trait Implementations§

Source§

impl Clone for ApplyOptions

Source§

fn clone(&self) -> ApplyOptions

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ApplyOptions

Source§

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

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

impl Default for ApplyOptions

Source§

fn default() -> Self

Creates a new ApplyOptions instance with default values.

This is the standard way to get a default configuration, which has dry_run set to false and fuzz_factor set to 0.7.

§Example
let options: ApplyOptions = Default::default();

assert_eq!(options.dry_run, false);
assert_eq!(options.fuzz_factor, 0.7);
Source§

impl PartialEq for ApplyOptions

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for ApplyOptions

Source§

impl StructuralPartialEq for ApplyOptions

Auto Trait Implementations§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.