reduct_base/msg/
bucket_api.rs1use crate::msg::entry_api::EntryInfo;
6use serde::{Deserialize, Serialize};
7use std::fmt::Display;
8use std::str::FromStr;
9
10#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
16pub enum QuotaType {
17 #[default]
18 NONE = 0,
19 FIFO = 1,
20 HARD = 2,
21}
22
23impl From<i32> for QuotaType {
24 fn from(value: i32) -> Self {
25 match value {
26 0 => QuotaType::NONE,
27 1 => QuotaType::FIFO,
28 2 => QuotaType::HARD,
29 _ => QuotaType::NONE,
30 }
31 }
32}
33
34impl FromStr for QuotaType {
35 type Err = ();
36
37 fn from_str(s: &str) -> Result<Self, Self::Err> {
38 match s {
39 "NONE" => Ok(QuotaType::NONE),
40 "FIFO" => Ok(QuotaType::FIFO),
41 "HARD" => Ok(QuotaType::HARD),
42 _ => Err(()),
43 }
44 }
45}
46
47impl Display for QuotaType {
48 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
49 match self {
50 QuotaType::NONE => write!(f, "NONE"),
51 QuotaType::FIFO => write!(f, "FIFO"),
52 QuotaType::HARD => write!(f, "HARD"),
53 }
54 }
55}
56
57#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
59pub struct BucketSettings {
60 pub quota_type: Option<QuotaType>,
62 pub quota_size: Option<u64>,
64 pub max_block_size: Option<u64>,
66 pub max_block_records: Option<u64>,
68}
69
70#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
72pub struct BucketInfo {
73 pub name: String,
75 pub entry_count: u64,
77 pub size: u64,
79 pub oldest_record: u64,
81 pub latest_record: u64,
83 pub is_provisioned: bool,
85}
86
87#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
89pub struct FullBucketInfo {
90 pub info: BucketInfo,
92 pub settings: BucketSettings,
94 pub entries: Vec<EntryInfo>,
96}
97
98#[cfg(test)]
99mod tests {
100 use super::*;
101 use rstest::rstest;
102
103 #[rstest]
104 #[case(QuotaType::NONE, "NONE")]
105 #[case(QuotaType::FIFO, "FIFO")]
106 #[case(QuotaType::HARD, "HARD")]
107 fn test_enum_as_string(#[case] quota_type: QuotaType, #[case] expected: &str) {
108 let settings = BucketSettings {
109 quota_type: Some(quota_type),
110 quota_size: Some(100),
111 max_block_size: Some(100),
112 max_block_records: Some(100),
113 };
114 let serialized = serde_json::to_string(&settings).unwrap();
115
116 assert_eq!(
117 serialized,
118 format!("{{\"quota_type\":\"{}\",\"quota_size\":100,\"max_block_size\":100,\"max_block_records\":100}}", expected)
119 );
120 }
121
122 #[rstest]
123 #[case(QuotaType::NONE, "NONE")]
124 #[case(QuotaType::FIFO, "FIFO")]
125 #[case(QuotaType::HARD, "HARD")]
126 fn test_quota_from_string(#[case] expected: QuotaType, #[case] as_string: &str) {
127 assert_eq!(QuotaType::from_str(as_string).unwrap(), expected);
128 }
129}
130
131#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
132pub struct RenameBucket {
133 pub new_name: String,
135}