rootless_run/traits.rs
1//! Traits for rootless backends.
2
3use std::process::Output;
4
5/// The options for a rootless backend.
6pub trait RootlessOptions {
7 /// Returns the options as a [`Vec`] of [`String`].
8 fn to_vec(&self) -> Vec<String>;
9}
10
11/// A backend for running a command as root.
12pub trait RootlessBackend<T>
13where
14 T: RootlessOptions,
15{
16 /// The Error type to use.
17 type Err;
18
19 /// Creates a new [`RootlessBackend`] from a [`RootlessOptions`].
20 fn new(options: T) -> Self
21 where
22 Self: Sized;
23
24 /// Returns the specific [`RootlessOptions`] used for the [`RootlessBackend`] implementation.
25 fn options(&self) -> &T;
26
27 /// Runs a command as root using the [`RootlessBackend`] implementation and returns the
28 /// resulting [`Output`].
29 fn run(&self, command: &[&str]) -> Result<Output, Self::Err>;
30}