pub trait PackageManager: Send + Sync {
// Required methods
fn name(&self) -> &str;
fn family(&self) -> Family;
fn command(
&self,
ctx: &Context,
verb: Verb,
args: &[OsString],
) -> Result<CommandSpec, PluginError>;
}Expand description
一个包管理器后端的实现。
§这是纯同步接口
没有 async、没有 trait object 回调、没有 I/O。原因见 crate 文档:跨 dlopen
边界传 Future 是这套方案里最脆的地方,而把接口压成「输入动词 + 参数,输出一条命令」
之后,跨边界的就只剩下普通数据了。
§它只应该做映射
见 crate 文档里的约束表。一句话:command() 的输入只有 Verb / args /
Context,输出只有 CommandSpec 或 PluginError。
Required Methods§
Sourcefn command(
&self,
ctx: &Context,
verb: Verb,
args: &[OsString],
) -> Result<CommandSpec, PluginError>
fn command( &self, ctx: &Context, verb: Verb, args: &[OsString], ) -> Result<CommandSpec, PluginError>
把「动词 + 参数」翻译成一条具体命令。
不支持某个动词时返回 PluginError::UnsupportedVerb,不要去凑一个近似命令。
宿主对 exec 有降级处理,其余动词会原样报错 —— 两种情况都比“猜一个“好。
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".