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: boolIf 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: f32The similarity threshold for fuzzy matching (0.0 to 1.0).
Higher is stricter. 0.0 disables fuzzy matching.
Implementations§
Source§impl ApplyOptions
impl ApplyOptions
Sourcepub fn new() -> Self
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);Sourcepub fn dry_run() -> Self
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);Sourcepub fn exact() -> Self
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);Sourcepub fn with_dry_run(self, dry_run: bool) -> Self
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);Sourcepub fn with_fuzz_factor(self, fuzz_factor: f32) -> Self
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);Sourcepub fn builder() -> ApplyOptionsBuilder
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
impl Clone for ApplyOptions
Source§fn clone(&self) -> ApplyOptions
fn clone(&self) -> ApplyOptions
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ApplyOptions
impl Debug for ApplyOptions
Source§impl Default for ApplyOptions
impl Default for ApplyOptions
Source§fn default() -> Self
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
impl PartialEq for ApplyOptions
impl Copy for ApplyOptions
impl StructuralPartialEq for ApplyOptions
Auto Trait Implementations§
impl Freeze for ApplyOptions
impl RefUnwindSafe for ApplyOptions
impl Send for ApplyOptions
impl Sync for ApplyOptions
impl Unpin for ApplyOptions
impl UnsafeUnpin for ApplyOptions
impl UnwindSafe for ApplyOptions
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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