我目前正在研究一个铁锈端口 https://github.com/JuxhinDB/twistrs某证券的tool https://github.com/elceef/dnstwist。与 Rust 的指南一致,我想将核心库隔离到自己的包中,以便我们可以创建与核心库交互的各种工具(CLI、API、流等),而无需将它们耦合在一起。
核心库公开了两个公共枚举,其中之一是PermutationMode
(截断):
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum PermutationMode {
All,
Addition,
BitSquatting,
Homoglyph,
}
使用创建 CLI 实用程序时Clap https://github.com/clap-rs/clap,我想扩展这个库 Enum 作为 CLI 的一部分,如下所示:
use clap::Clap;
use twistrs::permutate::PermutationMode;
#[derive(Clap, PartialEq, Debug)]
#[clap(name = "twistrs-cli")]
struct Opts {
#[clap(short, long)]
registered_domains: bool,
#[clap(arg_enum)]
permutation_mode: PermutationMode,
}
这样,在调用 CLI 时,我们可以将排列模式从用户无缝传递到 CLI、库,并且 CLI 无需了解内部模式(如果库添加了更多模式)。
./twist-cli --registered-domains --permutation_mode=all example.com
目前这似乎不可能(这是有道理的)。一种尝试是使用类型别名:
#[derive(Clap)]
type ArgPermutationMode = PermutationMode
但是,我们不能将派生宏用于类型别名。我还尝试“克隆”枚举并尝试映射到库枚举:
enum ArgPermutationMode {
PermutationMode::All,
}
哪个不编译。
Question- 是否可以扩展内部库枚举以将其用作 Clap 参数?