Skip to main content

AsyncCommand

Trait AsyncCommand 

Source
pub trait AsyncCommand<S, E, P>
where E: Error + Send, P: ProcessStatus<S, E> + Send, Self: Sized,
{ // Required methods fn new<A, B>( executable_path: &OsStr, args: A, process_type: P, ) -> Result<Self, E> where A: IntoIterator<Item = B>, B: AsRef<OsStr>; async fn execute(&mut self, timeout: Option<Duration>) -> Result<S, E>; }
Expand description

Trait for types that can spawn and execute an OS process asynchronously.

The type parameter S is the success-status type (e.g. crate::pg_enums::PgServerStatus), E is the error type, and P is the ProcessStatus implementation that provides status/error mappings.

Self: Sized means this trait cannot be used as a dyn trait object. Use the concrete AsyncCommandExecutor directly.

Required Methods§

Source

fn new<A, B>( executable_path: &OsStr, args: A, process_type: P, ) -> Result<Self, E>
where A: IntoIterator<Item = B>, B: AsRef<OsStr>,

Creates and spawns a new OS process.

§Arguments
  • executable_path — Path to the executable (e.g. initdb, pg_ctl).
  • args — Command-line arguments to pass to the executable.
  • process_type — The ProcessStatus value describing this process.
§Errors

Returns E::error_type() if the process cannot be spawned.

Source

async fn execute(&mut self, timeout: Option<Duration>) -> Result<S, E>

Waits for the process to finish, optionally enforcing a deadline.

Stdout and stderr are captured and forwarded to the log crate (at info level) in background tasks.

§Arguments
  • timeout — If Some(duration), the process is killed and an error is returned if it does not finish within duration. None waits indefinitely.
§Returns

The ProcessStatus::status_exit value on success.

§Errors

Returns ProcessStatus::timeout_error if the deadline is exceeded. Returns ProcessStatus::error_type if the process exits with a non-zero status. Returns a wrapped error from ProcessStatus::wrap_error if waiting on the process fails.

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.

Implementors§

Source§

impl<S, E, P> AsyncCommand<S, E, P> for AsyncCommandExecutor<S, E, P>
where S: Send, E: Error + Send, P: ProcessStatus<S, E> + Send,