pub trait BwCommand {
type Client: ClientState;
// Required method
async fn run(self, client: Self::Client) -> Result<CommandOutput>;
}Expand description
Trait implemented by commands that participate in the typestate dispatch.
Commands that don’t depend on auth/lock state (e.g. shell-completion generation, base64
encoding) use AnyState as their Client.
Call sites invoke commands via BwCommandExt::dispatch rather than calling run
directly; the extension trait performs the typestate extraction in one place.
§Example
ⓘ
use crate::client_state::{BwCommand, LoggedIn};
use crate::render::CommandResult;
pub struct SyncArgs;
impl BwCommand for SyncArgs {
type Client = LoggedIn;
async fn run(self, LoggedIn { user, .. }: LoggedIn) -> CommandResult {
user.sync().sync(Default::default()).await?;
Ok("Synced.".into())
}
}Required Associated Types§
type Client: ClientState
Required Methods§
async fn run(self, client: Self::Client) -> Result<CommandOutput>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.