Skip to main content

client_trait

Attribute Macro client_trait 

Source
#[client_trait]
Expand description

Attribute macro that emits the FromClientShared bridge for a hand-written feature client trait.

Applied to a trait FooTrait { ... } declaration with a via = <expression> argument, it re-emits the trait unchanged and adds:

impl FromClientShared for dyn FooTrait {
    fn from_client_shared(client: &Client) -> Arc<Self> {
        Arc::new(<expression>)
    }
}

The expression has client: &Client in scope and must evaluate to a value that can be wrapped in Arc<dyn FooTrait> (typically a concrete struct that implements the trait).

§Example

#[client_trait(via = client.folders())]
#[cfg_attr(any(test, feature = "test-fixtures"), mockall::automock)]
#[async_trait::async_trait]
pub trait FoldersClientTrait: Send + Sync {
    async fn get(&self, id: FolderId) -> Result<FolderView, FolderError>;
}