Skip to main content

Module protocol

Module protocol 

Source
Expand description

The hidden __handler protocol between #[handlers] and a transport’s handler attribute (transports DESIGN §2.1, §2.5, X1, X2).

#[handlers] expands first. For each handler it removes the method’s enhancer and #[meta] attributes and appends, after the transport attribute,

#[::ulo::__private::__handler(<name>,
    controller(<impl-level enhancer attrs>),
    method(<method-level enhancer attrs>),
    meta(controller(<impl-level meta exprs>), method(<method-level meta exprs>)))]

A method-level enhancer attribute or meta expression written inside cfg_attr carries one #[cfg(<predicate>)] per enclosing predicate in front of it, method(#[cfg(feature = "x")] guards(AuthGuard)), and whatever a transport generates from it is compiled under those gates (EnhancerAttr::gates, MetaExpr::gates). A handler whose transport attribute sits inside cfg_attr receives the attribute inside a cfg_attr with the same predicates, so it is present exactly where the transport attribute is.

The transport attribute removes it with take_handler_attr and owes three items inside the impl, every <name> the method’s identifier without r#:

  1. const __ULO_KEY_<name>: &'static str = <Tr as ::ulo::Transport>::KEY; (X1).
  2. const __ULO_CHECKS_<name>: () = { .. };, the pairwise body-consumer assertions, () when the handler has fewer than two parameters. #[handlers] reads it from a free const _: () = <Ctrl>::__ULO_CHECKS_<name>;, which evaluates it unconditionally, or on a generic controller from Handlers::mount, which evaluates it when mount is instantiated.
  3. fn __ulo_mount_<name><__UloV0, ..>(m: &mut ::ulo::Mount<'_>, shared: &::ulo::__private::Shared<(Arc<__UloV0>, ..)>), one type parameter per impl-level value entry in the order written across the impl’s enhancer attributes, each bounded by its role for this transport when the entry applies to it and unbounded otherwise (X2). #[handlers]’s Handlers::mount builds the Shared once and calls every mount function with it.

crate::emit::MountFn writes all three.

Re-exports§

pub use enhancers::EnhancerAttr;
pub use enhancers::Entry;
pub use enhancers::Form;
pub use enhancers::Role;
pub use scope::SCOPE_WORDS;
pub use scope::ScopeArg;

Modules§

enhancers
The enhancer attributes’ grammar, shared by #[handlers], which parses them off the impl and its methods, and by every transport attribute, which reads them back out of __handler.
scope
The scope word, written the same way wherever a scope is declared: #[injectable(execution)] on a type, with(execution) = .. on a closure.

Structs§

HandlerTokens
The tokens __handler(..) carries for one handler.
MetaExpr
One #[meta(..)] expression.
MetaTokens
The #[meta(..)] expressions of one handler, at both tiers, in the order written.

Functions§

is_meta
Whether attr is #[meta(..)], by its path’s last segment.
meta_exprs
The expressions of one #[meta(..)], each compiled under gates.
outside_handlers
The error a transport attribute named attr_name reports when take_handler_attr finds no __handler: it sits outside a #[handlers] impl, or inside one on a method where #[handlers] took another attribute for the transport attribute and gated the hand-off on that one’s cfg_attr.
take_handler_attr
Removes the __handler attribute #[handlers] appended to a handler and parses it. None when the method carries none, which the transport attribute reports with outside_handlers.
take_meta
The #[meta(..)] attributes in attrs, removed and parsed, their expressions in order and ungated.