diff --git a/core/src/types/builder.rs b/core/src/types/builder.rs index 1ae9a993f1e1..cc2a4895286b 100644 --- a/core/src/types/builder.rs +++ b/core/src/types/builder.rs @@ -174,7 +174,7 @@ pub trait Configurator: Serialize + DeserializeOwned + Debug + 'static { // TODO: we are not interpreting the host or path params // the `let op = Operator::from_uri("fs:///tmp/test", vec![])?;` statement from the RFC wont work. // instead we should use `let op = Operator::from_uri("fs://?root=/tmp/test", vec![])?;` as done - // in `ofs` + // in `ofs`. The `fs` service should override this default implementation if it wants to use the host or path params? // TODO: should we merge it this way? let merged_options = url_options.into_iter().chain(options); diff --git a/core/src/types/operator/builder.rs b/core/src/types/operator/builder.rs index bad3917bc174..21b98be9e87a 100644 --- a/core/src/types/operator/builder.rs +++ b/core/src/types/operator/builder.rs @@ -98,6 +98,14 @@ impl Operator { } /// TODO: document this. + /// + /// TODO: improve those examples + /// # Examples + /// ``` + /// let op = Operator::from_uri("fs://?root=/tmp/test", vec![])? + /// + /// Ok(()) + /// ``` pub fn from_uri( uri: &str, options: impl IntoIterator, diff --git a/core/src/types/operator/registry.rs b/core/src/types/operator/registry.rs index 466383c66fd4..a1adb6beb530 100644 --- a/core/src/types/operator/registry.rs +++ b/core/src/types/operator/registry.rs @@ -38,15 +38,18 @@ impl OperatorRegistry { uri: &str, options: impl IntoIterator, ) -> Result { - let parsed_uri = http::Uri::try_from(uri).map_err(|err| { + // TODO: we use the `url::Url` struct instead of `http:Uri`, because + // we needed it in `Configurator::from_uri` method. + let parsed_url = url::Url::parse(uri).map_err(|err| { Error::new(ErrorKind::ConfigInvalid, "uri is invalid") .with_context("uri", uri) .set_source(err) })?; - let scheme = parsed_uri.scheme_str().ok_or_else(|| { - Error::new(ErrorKind::ConfigInvalid, "uri is missing scheme").with_context("uri", uri) - })?; + // TODO: with the `url::Url` struct, we always have the scheme (it is not an Option) + // but with the `http::Uri` crate, it can be missing https://docs.rs/http/latest/http/uri/struct.Uri.html#method.scheme + // which one should we use? + let scheme = parsed_url.scheme(); let factory = self.registry.get(scheme).ok_or_else(|| { Error::new(