pub trait Control: Sealed {
type Result;
// Required methods
fn memory_limit(self, limit: usize) -> Self;
fn time_limit(self, limit: Duration) -> Self;
fn strict_errors(self) -> Self;
fn terminate_for_timeout(self) -> Self;
fn stdout_filter<T>(self, listener: T) -> Self
where Self: Control<Result = Output>,
T: PipeFilter;
fn stderr_filter<T>(self, listener: T) -> Self
where Self: Control<Result = Output>,
T: PipeFilter;
fn wait(self) -> Result<Option<Self::Result>>;
}
Expand description
A temporary wrapper for process limits.
Required Associated Types§
Required Methods§
Sourcefn memory_limit(self, limit: usize) -> Self
Available on Android, or Linux and (GNU or musl), or Windows only.
fn memory_limit(self, limit: usize) -> Self
Sets the total virtual memory limit for the process in bytes.
If the process attempts to allocate memory in excess of this limit, the allocation will fail. The type of failure will depend on the platform, and the process might terminate if it cannot handle it.
Small memory limits are safe, but they might prevent the operating system from starting the process.
Sourcefn time_limit(self, limit: Duration) -> Self
fn time_limit(self, limit: Duration) -> Self
Sets the total time limit for the process in milliseconds.
A process that exceeds this limit will not be terminated unless
terminate_for_timeout
is called.
Sourcefn strict_errors(self) -> Self
fn strict_errors(self) -> Self
Causes wait
to never suppress an error.
Typically, errors terminating the process will be ignored, as they are often less important than the result. However, when this method is called, those errors will be returned as well.
Sourcefn terminate_for_timeout(self) -> Self
fn terminate_for_timeout(self) -> Self
Causes the process to be terminated if it exceeds the time limit.
Process identifier reuse by the system will be mitigated. There should never be a scenario that causes an unintended process to be terminated.
Sourcefn stdout_filter<T>(self, listener: T) -> Self
fn stdout_filter<T>(self, listener: T) -> Self
Calls a filter function for each write to stdout.
For more information, see PipeFilter
.
§Panics
Panics if Command::stdout
has not been set to Stdio::piped
.
Sourcefn stderr_filter<T>(self, listener: T) -> Self
fn stderr_filter<T>(self, listener: T) -> Self
Calls a filter function for each write to stderr.
For more information, see PipeFilter
.
§Panics
Panics if Command::stderr
has not been set to Stdio::piped
.
Sourcefn wait(self) -> Result<Option<Self::Result>>
fn wait(self) -> Result<Option<Self::Result>>
Runs the process to completion, aborting if it exceeds the time limit.
At least one additional thread might be created to wait on the process without blocking the current thread.
If the time limit is exceeded before the process finishes, Ok(None)
will be returned. However, the process will not be terminated in that
case unless terminate_for_timeout
is called beforehand. It is
recommended to always call that method to allow system resources to be
freed.
The stdin handle to the process, if it exists, will be closed before waiting. Otherwise, the process would assuredly time out when reading from that pipe.
This method cannot guarantee that the same io::ErrorKind
variants
will be returned in the future for the same types of failures. Allowing
these breakages is required to enable calling Child::kill
internally.
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.