FlossCommand

Struct FlossCommand 

Source
#[non_exhaustive]
pub struct FlossCommand { /* private fields */ }
Expand description

一次具体的 FLOSS 调用(可透传任意参数,保证“全功能”覆盖)。

Implementations§

Source§

impl FlossCommand

Source

pub fn arg<Argument>(self, arg: Argument) -> Self
where Argument: Into<OsString>,

追加一个原始参数(完全透传,不做语义校验)。

Source

pub fn args<Arguments, Argument>(self, args: Arguments) -> Self
where Arguments: IntoIterator<Item = Argument>, Argument: Into<OsString>,

追加多个原始参数(完全透传,不做语义校验)。

Source

pub fn command_line(&self) -> CommandLine

返回本次调用的命令行信息(含 -- 与 sample)。

Source

pub async fn run(self) -> Result<FlossOutput>

执行命令并检查退出码(非 0 返回 FlossError::NonZeroExit)。

§Errors
  • 当启动进程失败时,返回 FlossError::Io
  • 当进程退出码非 0 时,返回 FlossError::NonZeroExit(包含 stdout/stderr)。
Source

pub async fn run_allow_exit_codes<Codes>( self, codes: Codes, ) -> Result<FlossOutput>
where Codes: IntoIterator<Item = i32> + Send, Codes::IntoIter: Send,

执行命令并允许指定退出码视为成功。

§Errors
  • 当启动进程失败时,返回 FlossError::Io
  • 当退出码不在允许列表时,返回 FlossError::NonZeroExit(包含 stdout/stderr)。
Source

pub async fn run_json<Output>(self) -> Result<Output>
where Output: DeserializeOwned,

以 JSON 方式运行 FLOSS 并反序列化输出。

  • 若未显式传入 -j/--json,会自动补上 -j
  • 该方法默认会检查退出码(非 0 直接返回错误)。
§Errors
  • 当启动进程失败时,返回 FlossError::Io
  • 当进程退出码非 0 时,返回 FlossError::NonZeroExit(包含 stdout/stderr)。
  • 当 stdout 不是有效 JSON 时,返回 FlossError::Json
Source

pub async fn run_results(self) -> Result<ResultDocument>

以 JSON 方式运行 FLOSS 并解析为 ResultDocument

  • 若未显式传入 -j/--json,会自动补上 -j
  • 该方法默认会检查退出码(非 0 直接返回错误)。
§Errors
  • 当启动进程失败时,返回 FlossError::Io
  • 当进程退出码非 0 时,返回 FlossError::NonZeroExit(包含 stdout/stderr)。
  • 当 stdout 不是有效 JSON 时,返回 FlossError::Json
Source

pub async fn run_raw(self) -> Result<FlossOutput>

执行命令并返回输出(不检查退出码)。

§Errors
  • 当启动进程失败时,返回 FlossError::Io
  • 当超时且无法终止进程时,返回 FlossError::TimedOutKillFailed
Source

pub async fn run_raw_limited( self, max_bytes: usize, ) -> Result<FlossOutputLimited>

执行命令并以固定上限读取 stdout/stderr(不检查退出码)。

  • 若输出超过 max_bytes,仅保留前 max_bytes 字节,剩余字节会被丢弃。
§Errors
  • 当启动进程失败时,返回 FlossError::Io
  • 当超过超时时间时,返回 FlossError::TimedOut(stdout/stderr 可能被截断)。
  • 当超时且无法终止进程时,返回 FlossError::TimedOutKillFailed
Source

pub async fn run_inherit(self) -> Result<ExitStatus>

执行命令并将 stdout/stderr 直连终端(不检查退出码)。

§Errors
  • 当启动进程失败时,返回 FlossError::Io
  • 当超过超时时间时,返回 FlossError::TimedOut(stderr/stdout 为空)。
  • 当超时且无法终止进程时,返回 FlossError::TimedOutKillFailed(stderr/stdout 为空)。
Source

pub async fn run_inherit_checked(self) -> Result<ExitStatus>

执行命令并将 stdout/stderr 直连终端(退出码非 0 返回错误)。

§Errors
  • 当启动进程失败时,返回 FlossError::Io
  • 当超过超时时间时,返回 FlossError::TimedOut(stderr/stdout 为空)。
  • 当超时且无法终止进程时,返回 FlossError::TimedOutKillFailed(stderr/stdout 为空)。
  • 当退出码非 0 时,返回 FlossError::NonZeroExit(stderr/stdout 为空)。
Source

pub fn spawn(self) -> Result<Child>

启动子进程并将 stdout/stderr 直连终端,返回 Child 由调用方管理。

注意:该方法不处理超时,由调用方自行管理。

§Errors
  • 当启动进程失败时,返回 FlossError::Io
Source

pub fn spawn_piped(self) -> Result<Child>

启动子进程并将 stdout/stderr 设为 piped,返回 Child 由调用方管理。

注意:该方法不处理超时,由调用方自行管理。

§Errors
  • 当启动进程失败时,返回 FlossError::Io
Source

pub fn sample<Sample>(self, sample: Sample) -> Self
where Sample: AsRef<Path>,

设置样本(FLOSS 的位置参数 sample)。

内部会自动插入 --,避免样本路径以 - 开头时被误解析为参数。

Source

pub const fn with_timeout(self, timeout: Duration) -> Self

设置执行超时:超过该时间会尝试终止子进程并返回 FlossError::TimedOut

Trait Implementations§

Source§

impl Clone for FlossCommand

Source§

fn clone(&self) -> FlossCommand

Returns a duplicate 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 FlossCommand

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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 T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.