tisonkun commented on code in PR #7196:
URL: https://github.com/apache/opendal/pull/7196#discussion_r2836956367
##########
core/core/src/types/operator/registry.rs:
##########
@@ -15,42 +15,38 @@
// specific language governing permissions and limitations
// under the License.
-use std::collections::HashMap;
-use std::sync::{LazyLock, Mutex};
-
use crate::types::builder::{Builder, Configurator};
use crate::types::{IntoOperatorUri, OperatorUri};
use crate::{Error, ErrorKind, Operator, Result};
+use std::collections::HashMap;
+use std::sync::{LazyLock, Mutex};
/// Factory signature used to construct [`Operator`] from a URI and extra
options.
pub type OperatorFactory = fn(&OperatorUri) -> Result<Operator>;
-/// Default registry used by [`Operator::from_uri`].
-///
-/// `memory` is always registered here since it's used pervasively in unit
tests
-/// and as a zero-dependency backend.
-///
-/// Other optional service registrations are handled by the facade crate
`opendal`.
-pub static DEFAULT_OPERATOR_REGISTRY: LazyLock<OperatorRegistry> =
LazyLock::new(|| {
- let registry = OperatorRegistry::new();
-
- crate::services::register_memory_service(®istry);
-
- registry
-});
-
/// Global registry that maps schemes to [`OperatorFactory`] functions.
-#[derive(Debug, Default)]
+#[derive(Debug)]
pub struct OperatorRegistry {
factories: Mutex<HashMap<String, OperatorFactory>>,
}
impl OperatorRegistry {
- /// Create a new, empty registry.
- pub fn new() -> Self {
- Self {
- factories: Mutex::new(HashMap::new()),
- }
+ /// Get the global registry.
+ pub fn get() -> &'static Self {
Review Comment:
Yes. Whether or not add a `new` method to allow users to build their own
registry can be a follow-up. From my experience is a quite rare requirement.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]