opendal/services/rocksdb/
config.rs1use std::fmt::Debug;
19
20use serde::Deserialize;
21use serde::Serialize;
22
23use super::backend::RocksdbBuilder;
24
25#[derive(Default, Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
27#[serde(default)]
28#[non_exhaustive]
29pub struct RocksdbConfig {
30 pub datadir: Option<String>,
32 pub root: Option<String>,
36}
37
38impl crate::Configurator for RocksdbConfig {
39 type Builder = RocksdbBuilder;
40
41 fn from_uri(uri: &crate::types::OperatorUri) -> crate::Result<Self> {
42 let mut map = uri.options().clone();
43
44 if let Some(path) = uri.root() {
45 if !path.is_empty() {
46 map.entry("datadir".to_string())
47 .or_insert_with(|| format!("/{path}"));
48 }
49 }
50
51 Self::from_iter(map)
52 }
53
54 fn into_builder(self) -> Self::Builder {
55 RocksdbBuilder { config: self }
56 }
57}
58
59#[cfg(test)]
60mod tests {
61 use super::*;
62 use crate::Configurator;
63 use crate::types::OperatorUri;
64
65 #[test]
66 fn from_uri_sets_datadir_and_root() {
67 let uri = OperatorUri::new(
68 "rocksdb:///var/db?root=namespace",
69 Vec::<(String, String)>::new(),
70 )
71 .unwrap();
72
73 let cfg = RocksdbConfig::from_uri(&uri).unwrap();
74 assert_eq!(cfg.datadir.as_deref(), Some("/var/db"));
75 assert_eq!(cfg.root.as_deref(), Some("namespace"));
76 }
77}