Skip to main content

helm_rs/
backend.rs

1//! The traits that connect typed commands to backends.
2
3use std::future::Future;
4
5use crate::error::Result;
6use crate::options::GlobalOptions;
7
8/// A typed Helm command (for example `Version`). The command struct holds the arguments and flags;
9/// `Output` is what a successful run yields.
10pub trait Command: Clone + Send + Sync + 'static {
11    /// The parsed result of the command.
12    type Output: Send + 'static;
13}
14
15/// Marker for types that can execute commands. A backend implements [`Execute`] for every command
16/// it supports.
17pub trait Backend: Send + Sync + 'static {}
18
19/// A backend that can run the command `C`.
20///
21/// `Helm::run` is bounded on this trait, so a command the backend does not cover is a compile
22/// error. Cancellation: dropping the returned future must not leave Helm state half-written where
23/// avoidable; the CLI backend kills the process for read-only commands but lets mutating commands
24/// (install, upgrade, rollback, ...) run to completion, because killing an upgrade leaves the
25/// release in `pending-upgrade`.
26pub trait Execute<C: Command>: Backend {
27    /// Runs `command` with the given global options.
28    fn execute(
29        &self,
30        options: &GlobalOptions,
31        command: &C,
32    ) -> impl Future<Output = Result<C::Output>> + Send;
33}