tensor_eigen/args/
derive.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use std::str::FromStr;

use super::*;

#[derive(Subcommand)]
pub enum DeriveSubcommands {
    AnchorDisc(AnchorDiscriminatorArgs),
}

#[derive(Clone, Debug, PartialEq, Eq)]
pub enum AnchorDiscriminatorKind {
    Account,
    Instruction,
}

impl FromStr for AnchorDiscriminatorKind {
    type Err = String;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s.to_lowercase().as_str() {
            "account" | "acc" | "a" => Self::Account,
            "instruction" | "ix" | "i" => Self::Instruction,
            _ => return Err(format!("Invalid discriminator kind: {}", s)),
        })
    }
}

#[derive(ClapArgs)]
pub struct AnchorDiscriminatorArgs {
    pub kind: AnchorDiscriminatorKind,
    pub name: String,
}