MCPcopy Create free account
hub / github.com/carllerche/assert-struct / Like

Interface Like

assert-struct/src/lib.rs:990–1005  ·  view source on GitHub ↗

A trait for pattern matching, similar to `PartialEq` but for flexible matching. The `Like` trait enables custom pattern matching logic beyond simple equality. It's primarily used with the `=~` operator in `assert_struct!` macro to support regex patterns, custom matching logic, and other pattern-based comparisons. # Examples ## Basic String Pattern Matching ``` # #[cfg(feature = "regex")] # { u

Source from the content-addressed store, hash-verified

988/// assert!(email.like(&pattern));
989/// ```
990pub trait Like<Rhs = Self> {
991 /// Returns `true` if `self` matches the pattern `other`.
992 ///
993 /// # Examples
994 ///
995 /// ```
996 /// # #[cfg(feature = "regex")]
997 /// # {
998 /// use assert_struct::Like;
999 ///
1000 /// let s = "test123";
1001 /// assert!(s.like(&r"\w+\d+"));
1002 /// # }
1003 /// ```
1004 fn like(&self, other: &Rhs) -> bool;
1005}
1006
1007// String/&str implementations for regex pattern matching
1008#[cfg(feature = "regex")]

Callers 1

into_patternMethod · 0.85

Implementers 3

lib.rsassert-struct/src/lib.rs
test_custom_like_implementationassert-struct/tests/like_macro_integra
test_custom_like_implementationassert-struct/tests/like_trait.rs

Calls

no outgoing calls

Tested by

no test coverage detected