tensor_eigen/args/
derive.rs

1use std::str::FromStr;
2
3use super::*;
4
5#[derive(Subcommand)]
6pub enum DeriveSubcommands {
7    AnchorDisc(AnchorDiscriminatorArgs),
8}
9
10#[derive(Clone, Debug, PartialEq, Eq)]
11pub enum AnchorDiscriminatorKind {
12    Account,
13    Instruction,
14}
15
16impl FromStr for AnchorDiscriminatorKind {
17    type Err = String;
18
19    fn from_str(s: &str) -> Result<Self, Self::Err> {
20        Ok(match s.to_lowercase().as_str() {
21            "account" | "acc" | "a" => Self::Account,
22            "instruction" | "ix" | "i" => Self::Instruction,
23            _ => return Err(format!("Invalid discriminator kind: {}", s)),
24        })
25    }
26}
27
28#[derive(ClapArgs)]
29pub struct AnchorDiscriminatorArgs {
30    pub kind: AnchorDiscriminatorKind,
31    pub name: String,
32}