opendal_service_vercel_blob/
config.rs1use std::fmt::Debug;
19
20use serde::Deserialize;
21use serde::Serialize;
22
23use super::backend::VercelBlobBuilder;
24
25#[derive(Default, Serialize, Deserialize, Clone, PartialEq, Eq)]
27#[serde(default)]
28#[non_exhaustive]
29pub struct VercelBlobConfig {
30 pub root: Option<String>,
34 pub token: Option<String>,
36}
37
38impl Debug for VercelBlobConfig {
39 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40 f.debug_struct("VercelBlobConfig")
41 .field("root", &self.root)
42 .finish_non_exhaustive()
43 }
44}
45
46impl opendal_core::Configurator for VercelBlobConfig {
47 type Builder = VercelBlobBuilder;
48
49 fn from_uri(uri: &opendal_core::OperatorUri) -> opendal_core::Result<Self> {
50 let mut map = uri.options().clone();
51
52 if let Some(root) = uri.root()
53 && !root.is_empty()
54 {
55 map.insert("root".to_string(), root.to_string());
56 }
57
58 Self::from_iter(map)
59 }
60
61 fn into_builder(self) -> Self::Builder {
62 VercelBlobBuilder { config: self }
63 }
64}
65
66#[cfg(test)]
67mod tests {
68 use super::*;
69 use opendal_core::Configurator;
70 use opendal_core::OperatorUri;
71
72 #[test]
73 fn from_uri_sets_root() {
74 let uri = OperatorUri::new(
75 "vercel-blob://project-assets/images",
76 Vec::<(String, String)>::new(),
77 )
78 .unwrap();
79
80 let cfg = VercelBlobConfig::from_uri(&uri).unwrap();
81 assert_eq!(cfg.root.as_deref(), Some("images"));
82 }
83}