Skip to main content

method

Attribute Macro method 

Source
#[method]
Expand description

Marks a helper method within an entity or trait impl block.

Helper methods are internal methods that can be called by other methods within the entity but are not exposed as RPC handlers. They follow the same state access rules as other methods:

  • &self — read-only access to state via self.state
  • &mut selfnot allowed (only #[activity] can mutate state)

All methods in an entity impl block must be annotated with one of: #[rpc], #[workflow], #[activity], or #[method].

§Example

#[entity_impl]
#[state(MyState)]
impl MyEntity {
    #[method]
    fn compute_bonus(&self, amount: i32) -> i32 {
        self.state.multiplier * amount
    }

    #[activity]
    async fn apply_bonus(&mut self, amount: i32) -> Result<i32, ClusterError> {
        self.state.value += self.compute_bonus(amount);
        Ok(self.state.value)
    }
}

§Visibility

#[method] is #[private] by default. Use #[protected] to make it callable from other entities.