Skip to main content

peer

Attribute Macro peer 

Source
#[peer]
Expand description

Attribute macro for individual child methods within a #[plexus_macros::activation] impl block.

Two method shapes are accepted:

ShapeRoleExample
fn NAME(&self) -> Child (no args)Static child — routing name is the method namefn mercury(&self) -> Mercury
fn NAME(&self, name: &str) -> Option<Child> (sync or async)Dynamic fallback dispatcherfn planet(&self, name: &str) -> Option<Planet>

The enclosing #[plexus_macros::activation] macro collects all #[child] methods and generates a ChildRouter impl whose get_child(name) dispatches over them. #[child] methods are not exposed as Plexus RPC methods — they contribute only to ChildRouter routing.

§Example

ⓘ
#[plexus_macros::activation(namespace = "solar")]
impl Solar {
    #[plexus_macros::child]
    fn mercury(&self) -> Mercury { self.mercury.clone() }

    #[plexus_macros::child]
    async fn planet(&self, name: &str) -> Option<Planet> {
        self.lookup_planet(name).await
    }
}

list = method and search = method name the sibling methods that stream a dynamic child’s names (#[plexus_macros::child(list = names)]). NEST-17: by path; the string form (list = "names") is accepted for one release with a deprecation warning.

§How the child inherits its caller (MACRO-20)

forward = same_service | identity_only | pass_through | anonymous picks the policy the emitted ChildRouter::forward_policy_for hands the child. A static child defaults to same_service: the same service as its parent, it keeps the caller whole (principal stamp, session, ceiling). Write #[plexus_macros::child(forward = identity_only)] for a deputy that must not see the caller’s session. A dynamic child keeps the framework default (IdentityOnly) unless it names one.

Used standalone (outside an #[activation] block) this attribute is a no-op that returns the function unchanged. NEST-7: an activation returned by name — a peer, in this process or across the network, typed by a contract’s peer trait or untyped:

ⓘ
#[plexus_macros::peer(list = integrations)]
async fn integration(&self, name: &str) -> Result<Box<dyn forge::ForgePeer>, PeerError> { … }
#[plexus_macros::peer(list = dendrites, search = find)]
async fn dendrite(&self, name: &str) -> Result<Box<dyn Peer>, PeerError> { … }

Inside #[plexus_macros::activation] the slot’s role is MethodRole::Peer { interface }, routing calls it (a typed peer checked against the slot’s interface first) and a failure is its typed error item. Outside it this attribute does nothing.