burrito_secrets/waiters/
recursive.rs1use crate::database::{Entry, Metadata};
7use serde::{Deserialize, Serialize};
8use std::collections::BTreeMap;
9use crate::waiters::Waiter;
10
11#[derive(Serialize, Deserialize)]
12#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
13pub struct Recursive {
14 pub children: Vec<Entry>,
15 #[serde(flatten)]
16 pub additional_fields: BTreeMap<String, bson::Bson>,
17}
18
19impl Recursive {
20 pub fn new(children: Vec<Entry>) -> Self {
21 Self { children, additional_fields: BTreeMap::new() }
22 }
23}
24
25impl Waiter for Recursive {
26 fn name() -> String {
27 "burrito_recursive".to_string()
28 }
29
30 fn version() -> String {
31 "0.0.0".to_string()
32 }
33
34 fn into_entry(self) -> Entry {
35 let entry = bson::to_document(&self).unwrap();
36
37 entry.and_defaults::<Self>()
38 }
39
40 fn from_entry(entry: Entry) -> anyhow::Result<Self> {
41 Self::verify_version(&entry)?;
42
43 let entry = bson::from_document(entry)?;
44
45 Ok(entry)
46 }
47}
48
49impl Metadata for Recursive {
50 fn set_meta(&mut self, metadata: (&str, impl Serialize)) {
51 self.additional_fields.insert(metadata.0.to_string(), bson::to_bson(&metadata.1).unwrap());
52 }
53
54 fn get_meta(&self, key: &str) -> Option<&bson::Bson> {
55 self.additional_fields.get(key)
56 }
57}