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: Stringcdylib 文件名主干前缀,如 "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: Stringwrapper 工程 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: Stringcrates.io 索引地址。可以指向镜像。
local_overrides: BTreeMap<String, PathBuf>本地路径覆盖:crate 名 → 本地目录。
生成 wrapper 工程时会写成它的 [patch.crates-io]。开发期用 ——
wrapper 住在 ~/.{id}/build/ 下,读不到宿主项目里的 .cargo/config.toml,
所以本地联调必须在这里显式指路。生产环境留空。
Implementations§
Source§impl KitConfig
impl KitConfig
Sourcepub fn new(id: impl Into<String>) -> Self
pub fn new(id: impl Into<String>) -> Self
用最少的信息起一个配置,其余字段给保守默认值。
默认值全部由 id 推导,并且互相自洽 —— 例如 id = "myapp" 会得到:
| 字段 | 值 |
|---|---|
manifest_name | myapp-plugin.toml |
crate_prefix | myapp-plugin- |
lib_stem_prefix | myapp_plugin_ |
entry_symbol | myapp_plugin_entry_v1 |
contract_crate | myapp-plugin |
仍然要自己填的是 wrapper_body(它引用的路径来自宿主的契约 crate)和
contract_version。
entry_symbol 不需要以 NUL 结尾 —— libloading 会自己补。
Sourcepub fn with_data_dir(self, dir: impl Into<PathBuf>) -> Self
pub fn with_data_dir(self, dir: impl Into<PathBuf>) -> Self
覆盖数据目录。
Sourcepub fn with_lock_timeout(self, t: Duration) -> Self
pub fn with_lock_timeout(self, t: Duration) -> Self
覆盖锁等待时间。
Sourcepub fn effective_target(&self) -> &str
pub fn effective_target(&self) -> &str
本次构建的 target triple。优先用配置里的覆盖值。
Sourcepub fn normalize_crate_name(&self, name: &str) -> String
pub fn normalize_crate_name(&self, name: &str) -> String
把 install() 收到的名字规范成完整 crate 名。
已带前缀的原样返回;否则补前缀。