liurenjie1024 commented on code in PR #1231: URL: https://github.com/apache/iceberg-rust/pull/1231#discussion_r2106848332
########## crates/catalog/rest/src/catalog.rs: ########## @@ -223,6 +226,74 @@ impl RestCatalogConfig { } } +/// Builder for [`RestCatalog`]. +#[derive(Debug)] +pub struct RestCatalogBuilder(RestCatalogConfig); + +impl Default for RestCatalogBuilder { + fn default() -> Self { + Self(RestCatalogConfig { + name: None, + uri: "".to_string(), + warehouse: None, + props: HashMap::new(), + client: None, + }) + } +} + +impl CatalogBuilder for RestCatalogBuilder { + type C = RestCatalog; + + fn name(&mut self, name: impl Into<String>) -> &mut Self { + self.0.name = Some(name.into()); + self + } + + fn uri(&mut self, uri: impl Into<String>) -> &mut Self { + self.0.uri = uri.into(); + self + } + + fn warehouse(&mut self, warehouse: impl Into<String>) -> &mut Self { + self.0.warehouse = Some(warehouse.into()); + self + } + + fn with_prop(&mut self, key: impl Into<String>, value: impl Into<String>) -> &mut Self { + self.0.props.insert(key.into(), value.into()); + self + } + + fn build(self) -> impl Future<Output = Result<Self::C>> { + let result = { + if self.0.name.is_none() { + Err(Error::new( + ErrorKind::DataInvalid, + "Catalog name is required", + )) + } else if self.0.uri.is_empty() { + Err(Error::new( + ErrorKind::DataInvalid, + "Catalog uri is required", + )) + } else { + Ok(RestCatalog::new(self.0)) + } + }; + + std::future::ready(result) + } +} + +impl RestCatalogBuilder { + /// Configures the catalog with a custom HTTP client. + pub fn with_client(&mut self, client: Client) -> &mut Self { Review Comment: cc @Xuanwo -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org