Skip to main content

DnyTask

Struct DnyTask 

Source
pub struct DnyTask {
    pub tag: String,
    pub main_code: String,
    pub deps: String,
    pub envs: HashMap<String, String>,
    pub cargo_config: Option<String>,
    pub is_release: bool,
}
Available on crate feature dyntest only.
Expand description

单个动态测试任务:main.rs 内容、依赖与运行配置的 Builder。

§Feature Requirement

需要同时启用 "dyntest" 与 "std" 特性。

§Examples

use lib_unknown::dyntest::DnyTask;

let task = DnyTask::new("hello", r#"fn main() { println!("hi"); }"#)
    .with_deps(r#"serde = "1""#)
    .with_env("RUST_BACKTRACE", "1")
    .with_release(false);
assert_eq!(task.tag, "hello");

Fields§

§tag: String

任务标识,用于结果回调用例区分;From 元组缺省时为 "unnamed_task"。

§main_code: String

待编译运行的 main.rs 源码。

§deps: String

追加到临时工程 [dependencies] 的依赖声明片段。

§envs: HashMap<String, String>

注入子进程的环境变量。

§cargo_config: Option<String>

写入临时工程 .cargo/config.toml 的配置,无则为 None。

§is_release: bool

是否以 --release 编译运行。

Implementations§

Source§

impl DnyTask

Source

pub fn new(tag: impl Into<String>, code: impl Into<String>) -> Self

以标识与 main.rs 源码创建任务,其余配置取默认值。

§Feature Requirement

需要同时启用 "dyntest" 与 "std" 特性。

§Examples
use lib_unknown::dyntest::DnyTask;

let task = DnyTask::new("t", "fn main() {}");
assert_eq!(task.tag, "t");
Source

pub fn with_deps(self, deps: impl Into<String>) -> Self

设置 [dependencies] 依赖声明片段。

§Feature Requirement

需要同时启用 "dyntest" 与 "std" 特性。

Source

pub fn with_env(self, key: impl Into<String>, value: impl Into<String>) -> Self

注入单个环境变量。

§Feature Requirement

需要同时启用 "dyntest" 与 "std" 特性。

Source

pub fn with_envs<I, K, V>(self, envs: I) -> Self
where I: IntoIterator<Item = (K, V)>, K: Into<String>, V: Into<String>,

批量注入环境变量。

§Feature Requirement

需要同时启用 "dyntest" 与 "std" 特性。

Source

pub fn with_cargo_config(self, config: impl Into<String>) -> Self

设置写入临时工程 .cargo/config.toml 的配置。

§Feature Requirement

需要同时启用 "dyntest" 与 "std" 特性。

Source

pub fn with_release(self, release: bool) -> Self

开启或关闭 release 模式。

§Feature Requirement

需要同时启用 "dyntest" 与 "std" 特性。

Trait Implementations§

Source§

impl Clone for DnyTask

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl From<(String, String, Option<String>)> for DnyTask

Source§

fn from(tuple: (String, String, Option<String>)) -> Self

Converts to this type from the input type.

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.