pub struct FunctionOperation { /* private fields */ }
Expand description

This structure represents a single command that is performed via a local code function instead of running an Executable in a SubProcOperation. This can be used for operations in a chain that the local program performs and avoids the need to create multiple chains around this functionality. For example, a chain of operations that midway through creates a tar file could use a SubProcOperation with the Executable("tar") or it could use a FunctionOperation that uses the Rust tar::Builder to generate the tar file via Rust functionality.

The first argument to the called function is the reference directory, the second is the input file(s) that should be processed, and the last is the output file that should be generated.

The reference directory would be the current directory for the command had it been a SubProcOperation. The actual current directory for this process is not set to this reference directory; handling of the reference directory is left up to the called function.

Implementations§

source§

impl FunctionOperation

source

pub fn calling<T>(n: &str, f: T) -> FunctionOperationwhere T: Fn(&Path, &ActualFile, &ActualFile) -> Result<()> + 'static,

Creates a new FunctionOperation that will call a local function instead of executing a command in a sub-process. This is useful for interleaving local processing into the command chain where that local processing is executed in proper sequence with the other commands. The local function is provided with the “argument list” that would have been passed on the command-line; this argument list will contain any input or output filenames that should be used by the function.

A local function execution in the chain can only pass an output file to the subsequent operation in the chain; more complex data exchange would need to be serialized into that output file and appropriately consumed by the next stage. This might initially seem awkward, but makes sense when you consider that most operations are executions in subprocesses that are in a separate address space already.

Trait Implementations§

source§

impl Clone for FunctionOperation

source§

fn clone(&self) -> FunctionOperation

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for FunctionOperation

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl FilesPrep for FunctionOperation

source§

fn set_dir<T>(&mut self, tgtdir: T) -> &mut Selfwhere T: AsRef<Path>,

Sets the directory from which the operation will be performed. The caller is responsible for ensuring any FileArg::Loc paths are valid when operating from that directory. This directory is usually a relative directory and is interpreted from the current working directory or the directory provided to the OpInterface::execute method.
source§

fn set_input_file(&mut self, fname: &FileArg) -> &mut Self

Sets the input file for the operation, overriding any previous input file specification.
source§

fn add_input_file(&mut self, fname: &FileArg) -> &mut Self

Appends the additional input file to the list of input files for this operation.
source§

fn has_input_file(&self) -> bool

Returns true if one or more input files have been specified for this operation.
source§

fn set_output_file(&mut self, fname: &FileArg) -> &mut Self

Sets the output file for the command, overriding any previous output file specification.
source§

fn has_explicit_output_file(&self) -> bool

Returns true if the output file has been explicitly specified as a location (instead of being a TBD, a Glob match, or a Temp file).
source§

impl OpInterface for FunctionOperation

source§

fn label(&self) -> String

Returns a short identifier of this operation, usually used for user-presented identification purposes.
source§

fn set_label(&mut self, new_label: &str) -> &mut Self

Allows the label for an operation to be updated. The label is usually used for user-presentation identification purposes.
source§

fn execute<Exec, P>( &mut self, executor: &Exec, cwd: &Option<P> ) -> Result<ActualFile>where P: AsRef<Path>, Exec: OsRun,

Executes this command in a subprocess in the specified directory (via the OsRun execution provided). The input and output files will be determined and added to the command-line as indicated by their NamedFile values. The successful result specifies the output file written (if any). Read more
source§

fn execute_here(&mut self, executor: &impl OsRun) -> Result<ActualFile>

Convenience method to execute an operation with a given crate::Executor in the current directory.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.