snops_common/state/
agent_mode.rs1use std::fmt::Display;
2
3#[derive(
4 Default, Clone, Copy, Debug, serde::Serialize, serde::Deserialize, clap::Parser, PartialEq, Eq,
5)]
6pub struct AgentModeOptions {
7 #[arg(long)]
9 pub validator: bool,
10
11 #[arg(long)]
13 pub prover: bool,
14
15 #[arg(long)]
17 pub client: bool,
18
19 #[arg(long)]
21 pub compute: bool,
22}
23
24impl From<AgentModeOptions> for u8 {
25 fn from(mode: AgentModeOptions) -> u8 {
26 (mode.validator as u8)
27 | (mode.prover as u8) << 1
28 | (mode.client as u8) << 2
29 | (mode.compute as u8) << 3
30 }
31}
32
33impl From<u8> for AgentModeOptions {
34 fn from(mode: u8) -> Self {
35 Self {
36 validator: mode & 1 != 0,
37 prover: mode & 1 << 1 != 0,
38 client: mode & 1 << 2 != 0,
39 compute: mode & 1 << 3 != 0,
40 }
41 }
42}
43
44impl Display for AgentModeOptions {
45 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
46 let mut s = String::new();
47 if self.validator {
48 s.push_str("validator");
49 }
50 if self.prover {
51 if !s.is_empty() {
52 s.push_str(", ");
53 }
54 s.push_str("prover");
55 }
56 if self.client {
57 if !s.is_empty() {
58 s.push_str(", ");
59 }
60 s.push_str("client");
61 }
62 if self.compute {
63 if !s.is_empty() {
64 s.push_str(", ");
65 }
66 s.push_str("compute");
67 }
68
69 f.write_str(&s)
70 }
71}