Skip to content

assert-struct v0.3.0

Choose a tag to compare

@carllerche carllerche released this 19 Feb 18:34
· 28 commits to main since this release
d527627

What's New

Set Pattern Support

New #(...) syntax for unordered collection matching. Each pattern in the set matches a distinct element, regardless of order.

// Exact set matching - collection must contain exactly these elements
assert_struct!(data, Data {
    tags: #("rust", "async", "fast"),
    ..
});

// Partial set matching - find elements matching each pattern, ignore the rest
assert_struct!(data, Data {
    scores: #(> 90, < 50, > 70, ..),
    ..
});

// Empty set matching
assert_struct!(data, Data {
    items: #(),
    ..
});

All existing patterns work within set patterns: comparisons, ranges, regex, nested structs, and more.

Bug Fixes

  • Suppressed spurious unreachable_patterns warnings for single-variant enums
  • Fixed a regression with index-based assertions on Vec fields

Upgrading

[dev-dependencies]
assert-struct = "0.3"