squib_api/schemas/
entropy.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Default, Deserialize)]
7#[serde(deny_unknown_fields)]
8pub struct RawEntropyConfig {
9 #[serde(default)]
11 pub rate_limiter: Option<serde_json::Value>,
12}
13
14#[derive(Debug, Clone, Default, Serialize)]
17#[non_exhaustive]
18pub struct EntropyConfig {
19 pub rate_limiter: Option<serde_json::Value>,
21}
22
23impl TryFrom<RawEntropyConfig> for EntropyConfig {
24 type Error = String;
25
26 fn try_from(raw: RawEntropyConfig) -> Result<Self, Self::Error> {
27 Ok(Self {
28 rate_limiter: raw.rate_limiter,
29 })
30 }
31}
32
33#[cfg(test)]
34mod tests {
35 use super::*;
36
37 #[test]
38 fn test_should_accept_empty_entropy_config() {
39 let cfg = EntropyConfig::try_from(RawEntropyConfig::default()).unwrap();
40 assert!(cfg.rate_limiter.is_none());
41 }
42
43 #[test]
44 fn test_should_reject_unknown_fields() {
45 let json = r#"{"unexpected":1}"#;
46 assert!(serde_json::from_str::<RawEntropyConfig>(json).is_err());
47 }
48}