### Get differ for path Source: https://docs.rs/goldenfile/latest/src/goldenfile/mint.rs.html Determines the appropriate diff function based on the file extension. ```APIDOC ## get_differ_for_path>(_path: P) -> Differ ### Description Get the diff function to use for a given file path. It defaults to text_diff for unknown extensions. ### Parameters #### Path Parameters - **_path** (P: AsRef) - Required - The path of the file. ### Returns - Differ - The selected diff function. ``` -------------------------------- ### Get File Length Source: https://docs.rs/goldenfile/latest/src/goldenfile/differs.rs.html Retrieves the length of a file in bytes. It uses `fs::metadata` and panics if there's an error during metadata retrieval. ```rust fn file_len(path: &Path) -> u64 { check_io(fs::metadata(path), "getting file length", path).len() } ``` -------------------------------- ### get_differ_for_path Source: https://docs.rs/goldenfile/latest/goldenfile/mint/fn.get_differ_for_path.html Get the diff function to use for a given file path. ```APIDOC ## Function get_differ_for_path ### Description Get the diff function to use for a given file path. ### Signature ```rust pub fn get_differ_for_path>(_path: P) -> Differ ``` ### Parameters * `_path`: A type `P` that implements `AsRef`, representing the file path. ### Returns A `Differ` object representing the diff function for the given path. ``` -------------------------------- ### Create a new goldenfile Mint Source: https://docs.rs/goldenfile/latest/src/goldenfile/mint.rs.html Initializes a new Mint instance, creating the goldenfile directory if it doesn't exist. Panics if directory creation fails. ```rust pub struct Mint { path: PathBuf, tempdir: TempDir, files: Vec<(PathBuf, Differ)>, create_empty: bool, } impl Mint { fn new_internal>(path: P, create_empty: bool) -> Self { let path = path.as_ref().to_path_buf(); let tempdir = TempDir::new().unwrap(); let mint = Mint { path, files: vec![], tempdir, create_empty, }; fs::create_dir_all(&mint.path).unwrap_or_else(|err| { panic!( "Failed to create goldenfile directory {:?}: {:?", mint.path, err ) }); mint } /// Create a new goldenfile Mint. pub fn new>(path: P) -> Self { Self::new_internal(path, true) } /// Create a new goldenfile Mint. Goldenfiles will only be created when non-empty. pub fn new_nonempty>(path: P) -> Self { Self::new_internal(path, false) } } ``` -------------------------------- ### Mint::new Source: https://docs.rs/goldenfile/latest/src/goldenfile/mint.rs.html Creates a new goldenfile Mint. Goldenfiles will be created even if they are empty. ```APIDOC ## Mint::new ### Description Creates a new goldenfile Mint. Goldenfiles will be created even if they are empty. ### Signature ```rust pub fn new>(path: P) -> Self ``` ### Parameters * `path` (P: AsRef) - The directory path where goldenfiles will be stored. ``` -------------------------------- ### Set Background Color using `bg()` or `on_red()` Source: https://docs.rs/goldenfile/latest/goldenfile/mint/struct.Mint.html Demonstrates setting the background color. Prefer using specific methods like `on_red()` over the general `bg()` method for conciseness. ```rust use yansi::{Paint, Color}; painted.bg(Color::Red); ``` ```rust use yansi::Paint; painted.on_red(); ``` -------------------------------- ### new Source: https://docs.rs/goldenfile/latest/goldenfile/mint/struct.Mint.html Creates a new `Painted` object with a default `Style`. ```APIDOC ## new ### Description Create a new `Painted` with a default `Style`. ### Method Signature `fn new(self) -> Painted` ### Constraints `Self: Sized` ### Returns - `Painted` - A new `Painted` object with default styling. ### Example ```rust // Assuming 'Painted' is a type that can be created with new() let default_painted = Painted::new(); ``` ``` -------------------------------- ### Mint::new Source: https://docs.rs/goldenfile/latest/goldenfile/mint/struct.Mint.html Creates a new goldenfile Mint, which will manage goldenfiles in the specified path. ```APIDOC ## Mint::new ### Description Create a new goldenfile Mint. ### Signature ```rust pub fn new>(path: P) -> Self ``` ``` -------------------------------- ### Create New Mint Source: https://docs.rs/goldenfile/latest/goldenfile/mint/struct.Mint.html Initializes a new Mint instance for managing golden files at the specified path. Use this when you want to create or update golden files. ```rust pub fn new>(path: P) -> Self ``` -------------------------------- ### Mint::new_nonempty Source: https://docs.rs/goldenfile/latest/src/goldenfile/mint.rs.html Creates a new goldenfile Mint. Goldenfiles will only be created when non-empty. ```APIDOC ## Mint::new_nonempty ### Description Creates a new goldenfile Mint. Goldenfiles will only be created when non-empty. ### Signature ```rust pub fn new_nonempty>(path: P) -> Self ``` ### Parameters * `path` (P: AsRef) - The directory path where goldenfiles will be stored. ``` -------------------------------- ### Create New Non-Empty Mint Source: https://docs.rs/goldenfile/latest/goldenfile/mint/struct.Mint.html Initializes a new Mint instance that only creates golden files when the content is non-empty. This is useful for avoiding empty files. ```rust pub fn new_nonempty>(path: P) -> Self ``` -------------------------------- ### Generate and Write to Goldenfiles Source: https://docs.rs/goldenfile/latest/goldenfile/index.html Use Mint to create new goldenfiles and write content to them. The comparison with checked-in versions happens when Mint goes out of scope. ```rust use goldenfile::Mint; use std::io::Write; let mut mint = Mint::new("tests/goldenfiles"); let mut file1 = mint.new_goldenfile("file1.txt").unwrap(); let mut file2 = mint.new_goldenfile("file2.txt").unwrap(); writeln!(file1, "Hello world!").unwrap(); writeln!(file2, "Foo bar!").unwrap(); ``` -------------------------------- ### Mint::new_goldenfile Source: https://docs.rs/goldenfile/latest/src/goldenfile/mint.rs.html Creates a new goldenfile using a differ inferred from the file extension. The returned File is a temporary file, not the goldenfile itself. ```APIDOC ## Mint::new_goldenfile ### Description Creates a new goldenfile using a differ inferred from the file extension. The returned File is a temporary file, not the goldenfile itself. ### Signature ```rust pub fn new_goldenfile>(&mut self, path: P) -> Result ``` ### Parameters * `path` (P: AsRef) - The path to the goldenfile relative to the mint's base path. ### Returns * `Result` - A `File` handle to the temporary goldenfile. ``` -------------------------------- ### Mint::new_goldenfile_with_differ Source: https://docs.rs/goldenfile/latest/src/goldenfile/mint.rs.html Creates a new goldenfile with the specified diff function. The returned File is a temporary file, not the goldenfile itself. ```APIDOC ## Mint::new_goldenfile_with_differ ### Description Creates a new goldenfile with the specified diff function. The returned File is a temporary file, not the goldenfile itself. ### Signature ```rust pub fn new_goldenfile_with_differ>(&mut self, path: P, differ: Differ) -> Result ``` ### Parameters * `path` (P: AsRef) - The path to the goldenfile relative to the mint's base path. * `differ` (Differ) - The differ function to use for comparing goldenfiles. ### Returns * `Result` - A `File` handle to the temporary goldenfile. ``` -------------------------------- ### Paint white() Method Source: https://docs.rs/goldenfile/latest/goldenfile/mint/struct.Mint.html Sets the foreground color to white using the `white()` method. This is a shorthand for `fg(Color::White)`. ```rust use yansi::Paint; painted.white(); ``` -------------------------------- ### Generate and Compare Golden Files in Rust Source: https://docs.rs/goldenfile/latest/src/goldenfile/lib.rs.html Use `Mint::new` to create a goldenfile manager and `new_goldenfile` to create or open files for writing. The comparison happens automatically when the `Mint` object goes out of scope. To update golden files, set the `UPDATE_GOLDENFILES` environment variable. ```rust use goldenfile::Mint; use std::io::Write; let mut mint = Mint::new("tests/goldenfiles"); let mut file1 = mint.new_goldenfile("file1.txt").unwrap(); let mut file2 = mint.new_goldenfile("file2.txt").unwrap(); writeln!(file1, "Hello world!").unwrap(); writeln!(file2, "Foo bar!").unwrap(); ``` -------------------------------- ### Compare Binary Files Source: https://docs.rs/goldenfile/latest/src/goldenfile/differs.rs.html Compares two files byte by byte. Panics if file sizes differ or if any byte mismatch is found, reporting the first differing byte's position. ```rust pub fn binary_diff(old: &Path, new: &Path) { let old_len = file_len(old); let new_len = file_len(new); if old_len != new_len { panic!( "File sizes differ: Old file is {} bytes, new file is {} bytes", old_len, new_len ); } let first_difference = file_byte_iter(old) .zip(file_byte_iter(new)) .position(|(old_byte, new_byte)| old_byte != new_byte); if let Some(position) = first_difference { panic!({"Files differ at byte {}", old.display(), position + 1}); } } ``` -------------------------------- ### whenever Source: https://docs.rs/goldenfile/latest/goldenfile/mint/struct.Mint.html Conditionally enables styling based on a `Condition`. Replaces any previous condition. ```APIDOC ## whenever ### Description Conditionally enable styling based on whether the `Condition` `value` applies. Replaces any previous condition. See the crate level docs for more details. ### Method Signature `fn whenever(&self, value: Condition) -> Painted<&T>` ### Parameters - **value** (`Condition`) - Description: The condition to check for enabling the style. ### Returns - `Painted<&T>` - A `Painted` object with the conditional styling applied. ### Example ```rust use yansi::{Paint, Condition}; painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY); ``` ``` -------------------------------- ### Paint green() Method Source: https://docs.rs/goldenfile/latest/goldenfile/mint/struct.Mint.html Sets the foreground color to green using the `green()` method. This is a shorthand for `fg(Color::Green)`. ```rust println!("{}", value.green()); ``` -------------------------------- ### Create a new goldenfile with specified differ Source: https://docs.rs/goldenfile/latest/src/goldenfile/mint.rs.html Creates a new temporary file for writing goldenfile content using a provided differ. Ensures the parent directory for the temporary file exists. Returns a `Result` which is the temporary file. ```rust /// Create a new goldenfile with the specified diff function. /// /// The returned File is a temporary file, not the goldenfile itself. pub fn new_goldenfile_with_differ< P: AsRef, >( &mut self, path: P, differ: Differ, ) -> Result { let abs_path = self.new_goldenpath_with_differ(path, differ)?; if let Some(abs_parent) = abs_path.parent() && abs_parent != self.tempdir.path() { fs::create_dir_all(abs_parent).unwrap_or_else(|err| { panic!( "Failed to create temporary subdirectory {:?}: {:?", abs_parent, err ) }); } let maybe_file = File::create(abs_path); if maybe_file.is_err() { self.files.pop(); } maybe_file } ``` -------------------------------- ### paint Source: https://docs.rs/goldenfile/latest/goldenfile/mint/struct.Mint.html Applies a style wholesale to the object, replacing any previous style. ```APIDOC ## paint ### Description Apply a style wholesale to `self`. Any previous style is replaced. ### Method Signature `fn paint(&self, style: S) -> Painted<&Self>` ### Constraints `S: Into