Thanks to visit codestin.com
Credit goes to docs.rs

Skip to main content

Comparator

Trait Comparator 

Source
pub trait Comparator:
    Send
    + Sync
    + 'static {
    // Required methods
    fn matches(&self, reference: &Snapshot, test: &Snapshot) -> bool;
    fn dyn_clone(&self) -> Box<dyn Comparator>;

    // Provided method
    fn matches_fully(&self, reference: &Snapshot, test: &Snapshot) -> bool { ... }
}
Expand description

Allows specific behavior to be invoked when Snapshots are compared.

This is intended for when custom Snapshot comparison behavior is desired. For example, two binary files that contain the same logical data but have different representations on disk (as might be the case with compressed images) could be compared with a Comparator that decompresses Snapshot data before comparing it.

To make a custom Comparator active, pass it to crate::settings::Settings::set_comparator or call with_settings! and provide an appropriate Comparator instance.

This trait requires 'static so that implementing structs can be stored in crate::settings::Settings.

Required Methods§

Source

fn matches(&self, reference: &Snapshot, test: &Snapshot) -> bool

Returns true if the contents of reference and test match.

This is the standard comparison used by assert_snapshot!.

Source

fn dyn_clone(&self) -> Box<dyn Comparator>

Returns a type-erased clone of self.

This is needed so that crate::settings::Settings (which provides the usual mechanism for setting a custom Comparator) can implement Clone.

Provided Methods§

Source

fn matches_fully(&self, reference: &Snapshot, test: &Snapshot) -> bool

Returns true if reference and test match fully, including metadata.

This is used when INSTA_REQUIRE_FULL_MATCH is enabled. The default implementation delegates to matches.

Implementors§