Matchable

Trait Matchable 

Source
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 fields

Provided Methods§

Source

fn get_length(&self) -> Option<usize>

Get the length of the value if supported (for strings, collections, etc.)

Source

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.

Source

fn get_field_path(&self, _path: &[&str]) -> Option<&dyn Any>

Get a nested field value by path. Default implementation walks through get_field calls.

Source

fn type_name(&self) -> &str

Get the type name as a string

Source

fn is_empty(&self) -> Option<bool>

Check if the value is considered “empty” (for collections, strings, options)

Source

fn is_none(&self) -> bool

Check if this is a None/null value (for Option types)

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.

Implementations on Foreign Types§

Source§

impl Matchable for &str

Source§

impl Matchable for bool

Source§

impl Matchable for char

Source§

impl Matchable for f32

Source§

impl Matchable for f64

Source§

impl Matchable for i8

Source§

impl Matchable for i16

Source§

impl Matchable for i32

Source§

impl Matchable for i64

Source§

impl Matchable for i128

Source§

impl Matchable for isize

Source§

impl Matchable for u8

Source§

impl Matchable for u16

Source§

impl Matchable for u32

Source§

impl Matchable for u64

Source§

impl Matchable for u128

Source§

impl Matchable for usize

Source§

impl Matchable for String

Source§

impl<K, V> Matchable for HashMap<K, V>
where K: Borrow<str> + Hash + Eq, V: PartialEq + 'static,

Source§

fn get_length(&self) -> Option<usize>

Source§

fn get_field(&self, field: &str) -> Option<&dyn Any>

Source§

fn is_empty(&self) -> Option<bool>

Source§

impl<T: Matchable + 'static> Matchable for Option<T>

Source§

fn get_length(&self) -> Option<usize>

Source§

fn get_field(&self, field: &str) -> Option<&dyn Any>

Source§

fn is_none(&self) -> bool

Source§

fn is_empty(&self) -> Option<bool>

Source§

impl<T: Matchable> Matchable for Vec<T>

Implementors§