我正在try 使用clap创建一个CLI应用程序.ACommand
的constructor是这样的:
impl Command {
pub fn new(name: impl Into<Str>) -> Self {...}
}
但我需要向那里传递一个从共享.so
库加载的名称.我可以使用它的唯一方式是:
let mut registry = Registry::new();
registry.load("./libapp_addon_no1.so").ok();
registry.load("./libapp_addon_no2.so").ok();
for command in registry.commands() {
// command.name is a String
cli = cli.subcommand(Command::new(&*command.name.clone().leak()));
}
这是可行的,但有没有更好的方法从String
的副本中产生Into<Str>
呢?