middleware_constructors

Macro middleware_constructors 

Source
macro_rules! middleware_constructors {
    ($middleware:ty, $agent:ty, $field:ident, $config:ty, $state_method:ident) => { ... };
}
Expand description

Helper macro for creating standard middleware layer constructors

This macro generates the common constructor patterns that most middleware layers need: new(), with_config(), and from_handle().

§Example

use acton_htmx::middleware::middleware_constructors;
use acton_htmx::state::ActonHtmxState;
use acton_reactive::prelude::AgentHandle;

pub struct MyMiddleware {
    agent_handle: AgentHandle<MyAgent>,
}

middleware_constructors!(
    MyMiddleware,        // Middleware type
    MyAgent,             // Agent type
    agent_handle,        // Field name for the handle
    MyConfig             // Config type
);

This generates:

impl MyMiddleware {
    pub fn new(state: &ActonHtmxState) -> Self {
        Self {
            agent_handle: state.my_agent().clone(),
        }
    }

    pub fn with_config(state: &ActonHtmxState, _config: MyConfig) -> Self {
        Self::new(state)
    }

    pub fn from_handle(handle: AgentHandle<MyAgent>) -> Self {
        Self {
            agent_handle: handle,
        }
    }
}