pub struct CommandResult {
pub stdout: CapturedOutput,
pub stderr: CapturedOutput,
pub stdin: CapturedInput,
pub code: i32,
}Expand description
Result type for virtual command operations
Fields§
§stdout: CapturedOutput§stderr: CapturedOutput§stdin: CapturedInput§code: i32Implementations§
Source§impl CommandResult
impl CommandResult
Sourcepub fn new(
stdout: impl Into<CapturedOutput>,
stderr: impl Into<CapturedOutput>,
code: i32,
) -> Self
pub fn new( stdout: impl Into<CapturedOutput>, stderr: impl Into<CapturedOutput>, code: i32, ) -> Self
Create a result with readable output snapshots and a writable input record.
Sourcepub fn success_empty() -> Self
pub fn success_empty() -> Self
Create an empty success result
Sourcepub fn error_with_code(stderr: impl Into<String>, code: i32) -> Self
pub fn error_with_code(stderr: impl Into<String>, code: i32) -> Self
Create an error result with custom exit code
Sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
Check if the command was successful
Sourcepub fn exit_code(&self) -> i32
pub fn exit_code(&self) -> i32
Exit code of the command.
This is an alias for the code field, mirroring the
exitCode alias exposed by the JavaScript implementation (issue #36).
Sourcepub fn error_for_status(self) -> Result<CommandResult>
pub fn error_for_status(self) -> Result<CommandResult>
Turn a failing result into crate::Error::CommandFailed.
This is the Rust counterpart of the JavaScript errexit mode: a
non-zero status becomes an error whose exit status is readable through
both crate::Error::code and crate::Error::exit_code (issue
#38). Successful results pass through unchanged.
use command_stream::utils::CommandResult;
let error = CommandResult::error_with_code("", 42)
.error_for_status()
.unwrap_err();
assert_eq!(error.code(), Some(42));
assert_eq!(error.exit_code(), error.code());Trait Implementations§
Source§impl Clone for CommandResult
impl Clone for CommandResult
Auto Trait Implementations§
impl Freeze for CommandResult
impl RefUnwindSafe for CommandResult
impl Send for CommandResult
impl Sync for CommandResult
impl Unpin for CommandResult
impl UnsafeUnpin for CommandResult
impl UnwindSafe for CommandResult
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.