qubit-function 0.16.0

Functional programming traits and Box/Rc/Arc adapters for Rust, inspired by Java functional interfaces
// =============================================================================
//    Copyright (c) 2025 - 2026 Haixing Hu.
//
//    SPDX-License-Identifier: Apache-2.0
//
//    Licensed under the Apache License, Version 2.0.
// =============================================================================
//! # Mutator Debug Display Macro
//!
//! Generates Debug and Display trait implementations for Mutator structs
//!
//! Generates standard Debug and Display trait implementations for Mutator
//! structs that have a `name: Option<String>` field.
//!
//! # Parameters
//!
//! * `$struct_name` - The struct name
//! * `$generic` - Generic parameter list (one type parameter)
//!
//! # Examples
//!
//! ```ignore
//! // For single type parameter
//! impl_mutator_debug_display!(BoxMutator<T>);
//! ```

/// Generates Debug and Display trait implementations for Mutator structs
///
/// This macro should be used at the top level (outside of any impl block)
/// to generate Debug and Display trait implementations for Mutator structs.
/// It generates standard Debug and Display trait implementations for Mutator
/// structs that have a `name: Option<String>` field.
///
/// # Parameters
///
/// * `$struct_name` - The struct name
/// * `$generic` - Generic parameter list (one type parameter)
///
/// # Usage Location
///
/// This macro should be used at the top level, outside of any impl block,
/// typically in the same file as the struct definition.
///
/// # Examples
///
/// ```ignore
/// // At the top level, outside of any impl block
/// impl_mutator_debug_display!(BoxMutator<T>);
/// ```
macro_rules! impl_mutator_debug_display {
    // Single generic parameter
    ($struct_name:ident < $generic:ident >) => {
        impl<$generic> std::fmt::Debug for $struct_name<$generic> {
            fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
                f.debug_struct(stringify!($struct_name))
                    .field("name", &self.metadata.name())
                    .field("function", &"<function>")
                    .finish()
            }
        }

        impl<$generic> std::fmt::Display for $struct_name<$generic> {
            fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
                match self.metadata.name() {
                    Some(name) => {
                        write!(f, "{}({})", stringify!($struct_name), name)
                    }
                    None => write!(f, "{}", stringify!($struct_name)),
                }
            }
        }
    };
}

pub(crate) use impl_mutator_debug_display;