Struct chainsop::FunctionOperation
source · 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
impl FunctionOperation
sourcepub fn calling<T>(n: &str, f: T) -> FunctionOperationwhere
T: Fn(&Path, &ActualFile, &ActualFile) -> Result<()> + 'static,
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
impl Clone for FunctionOperation
source§fn clone(&self) -> FunctionOperation
fn clone(&self) -> FunctionOperation
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for FunctionOperation
impl Debug for FunctionOperation
source§impl FilesPrep for FunctionOperation
impl FilesPrep for FunctionOperation
source§fn set_dir<T>(&mut self, tgtdir: T) -> &mut Selfwhere
T: AsRef<Path>,
fn set_dir<T>(&mut self, tgtdir: T) -> &mut Selfwhere T: AsRef<Path>,
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
fn set_input_file(&mut self, fname: &FileArg) -> &mut Self
source§fn add_input_file(&mut self, fname: &FileArg) -> &mut Self
fn add_input_file(&mut self, fname: &FileArg) -> &mut Self
source§fn has_input_file(&self) -> bool
fn has_input_file(&self) -> bool
source§fn set_output_file(&mut self, fname: &FileArg) -> &mut Self
fn set_output_file(&mut self, fname: &FileArg) -> &mut Self
source§fn has_explicit_output_file(&self) -> bool
fn has_explicit_output_file(&self) -> bool
source§impl OpInterface for FunctionOperation
impl OpInterface for FunctionOperation
source§fn label(&self) -> String
fn label(&self) -> String
source§fn set_label(&mut self, new_label: &str) -> &mut Self
fn set_label(&mut self, new_label: &str) -> &mut Self
source§fn execute<Exec, P>(
&mut self,
executor: &Exec,
cwd: &Option<P>
) -> Result<ActualFile>where
P: AsRef<Path>,
Exec: OsRun,
fn execute<Exec, P>( &mut self, executor: &Exec, cwd: &Option<P> ) -> Result<ActualFile>where P: AsRef<Path>, Exec: OsRun,
NamedFile
values.
The successful result specifies the output file written (if any). Read more