hank_types/
lib.rs

1// @generated
2#[cfg(feature = "hank")]
3// @@protoc_insertion_point(attribute:hank)
4pub mod hank {
5    include!("hank.rs");
6    // @@protoc_insertion_point(hank)
7    #[cfg(feature = "hank-access_check")]
8    // @@protoc_insertion_point(attribute:hank.access_check)
9    pub mod access_check {
10        include!("hank.access_check.rs");
11        // @@protoc_insertion_point(hank.access_check)
12    }
13    #[cfg(feature = "hank-channel")]
14    // @@protoc_insertion_point(attribute:hank.channel)
15    pub mod channel {
16        include!("hank.channel.rs");
17        // @@protoc_insertion_point(hank.channel)
18    }
19    #[cfg(feature = "hank-cron")]
20    // @@protoc_insertion_point(attribute:hank.cron)
21    pub mod cron {
22        include!("hank.cron.rs");
23        // @@protoc_insertion_point(hank.cron)
24    }
25    #[cfg(feature = "hank-database")]
26    // @@protoc_insertion_point(attribute:hank.database)
27    pub mod database {
28        include!("hank.database.rs");
29        // @@protoc_insertion_point(hank.database)
30    }
31    #[cfg(feature = "hank-message")]
32    // @@protoc_insertion_point(attribute:hank.message)
33    pub mod message {
34        include!("hank.message.rs");
35        // @@protoc_insertion_point(hank.message)
36    }
37    #[cfg(feature = "hank-plugin")]
38    // @@protoc_insertion_point(attribute:hank.plugin)
39    pub mod plugin {
40        include!("hank.plugin.rs");
41        // @@protoc_insertion_point(hank.plugin)
42    }
43    #[cfg(feature = "hank-user")]
44    // @@protoc_insertion_point(attribute:hank.user)
45    pub mod user {
46        include!("hank.user.rs");
47        // @@protoc_insertion_point(hank.user)
48    }
49}
50// Customizations from lib.customizations.rs
51pub use hank::*;
52pub use prost_types::{Timestamp, TimestampError};
53
54impl serde::ser::Serialize for access_check::AccessCheckChain {
55    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
56    where
57        S: serde::ser::Serializer,
58    {
59        use serde::ser::SerializeStruct as _;
60        let mut state = serializer.serialize_struct("AccessCheckChain", 1)?;
61        state.serialize_field(
62            access_check::AccessCheckOperator::try_from(self.operator)
63                .expect("invalid access check operator")
64                .as_str_name(),
65            &self.checks,
66        )?;
67
68        state.end()
69    }
70}
71
72impl<'de> serde::de::Deserialize<'de> for access_check::AccessCheckChain {
73    fn deserialize<D: serde::de::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
74        let d: std::collections::BTreeMap<String, Vec<access_check::AccessCheck>> =
75            std::collections::BTreeMap::deserialize(d)?;
76
77        let (operator, checks) = d.first_key_value().expect("invalid access chain format");
78        Ok(access_check::AccessCheckChain {
79            operator: access_check::AccessCheckOperator::from_str_name(operator)
80                .expect("invalid access check operator")
81                .into(),
82            checks: checks.to_vec(),
83        })
84    }
85}
86
87#[derive(Default)]
88pub struct InstructionBuilder<T>
89where
90    T: Default + prost::Message,
91{
92    kind: plugin::InstructionKind,
93    input: T,
94    target: Option<String>,
95}
96
97impl<T> InstructionBuilder<T>
98where
99    T: Default + prost::Message,
100{
101    pub fn new(kind: plugin::InstructionKind) -> Self {
102        Self {
103            kind,
104            ..Default::default()
105        }
106    }
107
108    pub fn with_input(self, input: T) -> Self {
109        Self { input, ..self }
110    }
111
112    pub fn with_target(self, target: String) -> Self {
113        Self {
114            target: Some(target),
115            ..self
116        }
117    }
118
119    pub fn build(self) -> plugin::Instruction {
120        self.into()
121    }
122}
123
124impl<T> From<InstructionBuilder<T>> for plugin::Instruction
125where
126    T: Default + prost::Message,
127{
128    fn from(value: InstructionBuilder<T>) -> Self {
129        plugin::Instruction {
130            kind: value.kind.into(),
131            input: value.input.encode_to_vec(),
132            target: value.target,
133        }
134    }
135}