Skip to main content

KitConfig

Struct KitConfig 

Source
pub struct KitConfig {
Show 15 fields pub id: String, pub manifest_name: String, pub crate_prefix: String, pub entry_symbol: Vec<u8>, pub lib_stem_prefix: String, pub contract_crate: String, pub contract_version: String, pub wrapper_edition: String, pub wrapper_body: String, pub data_dir: Option<PathBuf>, pub lock_timeout: Duration, pub prefer_prebuilt: bool, pub target_triple: Option<String>, pub registry: String, pub local_overrides: BTreeMap<String, PathBuf>,
}
Expand description

一个 kit 实例的全部可配置项。

Fields§

§id: String

应用 id。决定数据目录 ~/.{id},也用作默认的 HTTP User-Agent 一部分。

§manifest_name: String

插件 manifest 的文件名,如 "bmux-plugin.toml"。

manifest 的 [plugin] / [lib] 两段由本 crate 定义(见 crate::manifest)。 宿主可以往同一个文件里追加自己的段(例如 bmux 的 [detect]),本 crate 会原样忽略。

§crate_prefix: String

插件 crate 名前缀,如 "bmux-plugin-"。

install("cargo") 会先补成 "bmux-plugin-cargo";已经带前缀的原样使用。

§entry_symbol: Vec<u8>

cdylib 导出的入口符号,如 b"bmux_plugin_entry_v1"。

§lib_stem_prefix: String

cdylib 文件名主干前缀,如 "bmux_plugin_"。

与「crate 名去掉前缀」拼接后,再加平台扩展名,得到实际文件名。 例:bmux-plugin-cargo → bmux_plugin_ + cargo → libbmux_plugin_cargo.so。

§contract_crate: String

宿主的契约 crate 名,如 "bmux-plugin"。生成的 wrapper 工程要依赖它。

§contract_version: String

契约 crate 的版本要求,如 "0.1"。

§wrapper_edition: String

生成的 wrapper 工程使用的 edition。

§wrapper_body: String

wrapper 工程 src/lib.rs 的内容模板。

{crate_ident} 会被替换成插件 crate 的 ident(- 换成 _)。 例(bmux):"bmux_plugin::export!({crate_ident}::create);\n"

§data_dir: Option<PathBuf>

数据目录覆盖。None = 用 ~/.{id}。

§lock_timeout: Duration

等待安装锁的超时时间。

§prefer_prebuilt: bool

安装时是否优先尝试 prebuilt 产物。

§target_triple: Option<String>

覆盖 target triple。None = 用编译期注入的 TARGET(见 build.rs)。

§registry: String

crates.io 索引地址。可以指向镜像。

§local_overrides: BTreeMap<String, PathBuf>

本地路径覆盖:crate 名 → 本地目录。

生成 wrapper 工程时会写成它的 [patch.crates-io]。开发期用 —— wrapper 住在 ~/.{id}/build/ 下,读不到宿主项目里的 .cargo/config.toml, 所以本地联调必须在这里显式指路。生产环境留空。

Implementations§

Source§

impl KitConfig

Source

pub fn new(id: impl Into<String>) -> Self

用最少的信息起一个配置,其余字段给保守默认值。

默认值全部由 id 推导,并且互相自洽 —— 例如 id = "myapp" 会得到:

字段值
manifest_namemyapp-plugin.toml
crate_prefixmyapp-plugin-
lib_stem_prefixmyapp_plugin_
entry_symbolmyapp_plugin_entry_v1
contract_cratemyapp-plugin

仍然要自己填的是 wrapper_body(它引用的路径来自宿主的契约 crate)和 contract_version。

entry_symbol 不需要以 NUL 结尾 —— libloading 会自己补。

Source

pub fn with_data_dir(self, dir: impl Into<PathBuf>) -> Self

覆盖数据目录。

Source

pub fn with_lock_timeout(self, t: Duration) -> Self

覆盖锁等待时间。

Source

pub fn effective_target(&self) -> &str

本次构建的 target triple。优先用配置里的覆盖值。

Source

pub fn normalize_crate_name(&self, name: &str) -> String

把 install() 收到的名字规范成完整 crate 名。

已带前缀的原样返回;否则补前缀。

Source

pub fn lib_stem(&self, crate_name: &str) -> String

由 crate 名推出 cdylib 文件名主干(不含 lib 前缀与扩展名)。

bmux-plugin-cargo → bmux_plugin_cargo

Source

pub fn paths(&self) -> KitResult<KitPaths>

解析出各项路径。会按需创建目录。

Trait Implementations§

Source§

impl Clone for KitConfig

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 Debug for KitConfig

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

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.