pub trait Matchable: PartialEq + Sized {
// Provided methods
fn get_length(&self) -> Option<usize> { ... }
fn get_field(&self, _field: &str) -> Option<&dyn Any> { ... }
fn get_field_path(&self, _path: &[&str]) -> Option<&dyn Any> { ... }
fn type_name(&self) -> &str { ... }
fn is_empty(&self) -> Option<bool> { ... }
fn is_none(&self) -> bool { ... }
}Expand description
Trait for types that can be matched against conditions.
This trait allows different types to opt-in to specific matching capabilities.
For structs, you can use #[derive(Matchable)] to automatically implement field access.
§Example
use condition_matcher::{Matchable, MatchableDerive};
use std::any::Any;
#[derive(MatchableDerive, PartialEq)]
struct MyStruct {
value: i32,
name: String,
}
// The derive macro automatically implements get_field for all fieldsProvided Methods§
Sourcefn get_length(&self) -> Option<usize>
fn get_length(&self) -> Option<usize>
Get the length of the value if supported (for strings, collections, etc.)
Sourcefn get_field(&self, _field: &str) -> Option<&dyn Any>
fn get_field(&self, _field: &str) -> Option<&dyn Any>
Get a field value by name as a type-erased reference. Returns None if field access is not supported or field doesn’t exist.
Sourcefn get_field_path(&self, _path: &[&str]) -> Option<&dyn Any>
fn get_field_path(&self, _path: &[&str]) -> Option<&dyn Any>
Get a nested field value by path. Default implementation walks through get_field calls.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.