Skip to main content

BinaryGolden

Struct BinaryGolden 

Source
pub struct BinaryGolden { /* private fields */ }
Expand description

A binary-content snapshot bound to a path on disk.

Like Golden but for arbitrary byte content. Useful for verifying generated images, archives, encoded protocol frames, etc.

On mismatch, the diff is reported as byte-length deltas and a hex preview of the first differing region — not a line-based diff, because binary content has no meaningful line structure.

Set the DEV_FIXTURES_UPDATE_GOLDEN environment variable to update snapshots on intentional changes.

§Example

use dev_fixtures::golden::BinaryGolden;
let dir = tempfile::tempdir().unwrap();
let path = dir.path().join("snap.bin");
std::fs::write(&path, &[0u8, 1, 2, 3]).unwrap();

let g = BinaryGolden::new(&path);
let check = g.compare("frame", &[0u8, 1, 2, 3]);
assert!(matches!(check.verdict, dev_report::Verdict::Pass));

Implementations§

Source§

impl BinaryGolden

Source

pub fn new(path: impl Into<PathBuf>) -> Self

Build a binary-golden bound to a path on disk.

Source

pub fn path(&self) -> &Path

The path this golden is bound to.

Source

pub fn compare(&self, name: impl AsRef<str>, actual: &[u8]) -> CheckResult

Compare actual against the stored snapshot and emit a CheckResult tagged fixtures and golden.

Verdicts mirror Golden::compare:

  • Match -> Pass.
  • Missing -> Skip with created tag (snapshot is written).
  • Mismatch + DEV_FIXTURES_UPDATE_GOLDEN set -> Skip with updated.
  • Mismatch -> Fail (Error) with regression tag, byte-length and first-diff-offset evidence.

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> 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, 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.