Skip to main content

method

Attribute Macro method 

Source
#[method]
Expand description

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

§Example

ⓘ
#[plexus::activation]                    // namespace "bash", implicitly
impl Bash {
    /// Execute a bash command
    #[plexus::method]
    async fn execute(&self, command: String) -> impl Stream<Item = BashEvent> {
        // ...
    }
}

§The return type is the contract (RETURNS-8)

Six forms: -> T, -> Result<T, E>, -> impl Stream<Item = T>, -> impl Stream<Item = Result<T, E>>, -> impl Stream<Item = Progress<T, P>>, -> impl Stream<Item = Result<Progress<T, P>, E>>. A plain return yields one item, impl Stream many; Result and Progress are recognised by name. Any other return type is a compile error that lists the six. returns(..) is removed (a compile error); streaming is a deprecated no-op on a stream form and an error on a one-item one.

§No in-call question (ASK-1)

bidirectional is removed (a compile error): a method never asks its caller mid-call, and Plexus has no in-call or protocol-wide confirmation. A method that wants its caller’s yes builds it from its own parameters (a dry_run, a plan id).

§Authorization arguments (R-1 / AUTHZ-CORE-2)

  • scope = "..." — explicit required scope, emitted into the generated MethodSchema.requires_credential. Repeatable: scope = "x.y", scope = "x.z" means the caller must satisfy ALL listed scopes (conjunction — AND, not OR). Literals are validated at compile time against the AUTHZ-CORE-4 scope grammar (dot-separated [a-z][a-z0-9_]* segments, optional trailing .* segment wildcard, or bare *).
  • input_window = N (BIDIR-6) — on a method with an Input<T> parameter, the credit it grants (default 64). input_max_buffered = N: the bytes held past which it grants no credit until drained (default 64 MiB). input_max_items = N, input_max_bytes = N: limits over the call’s life, none unless given. An Input<T> is at most one, top-level, and not one of the params: MethodSchema.input is T’s schema, and the client takes a stream.
  • public — the method is exempt from the default-deny gate; emitted as MethodSchema.public = true. Mixing public with scope = "..." is a compile error (a public method has no required scope to enforce).
  • Neither — the implicit <activation>.<method> scope rule applies at registry-build time (AUTHZ-CORE-4); the schema carries no requires_credential for the implicit case.