From 1064a1d46b57684722ce793d26e9c43cad7bc79d Mon Sep 17 00:00:00 2001 From: onewe Date: Fri, 10 May 2024 21:36:54 +0800 Subject: [PATCH] remove Extension constraint --- dubbo/src/extension/invoker_extension.rs | 5 ++++- dubbo/src/extension/mod.rs | 3 +-- dubbo/src/extension/registry_extension.rs | 4 ++++ examples/greeter/src/greeter/client.rs | 3 ++- examples/greeter/src/greeter/server.rs | 3 ++- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/dubbo/src/extension/invoker_extension.rs b/dubbo/src/extension/invoker_extension.rs index a92e4b72..58e5a2b6 100644 --- a/dubbo/src/extension/invoker_extension.rs +++ b/dubbo/src/extension/invoker_extension.rs @@ -8,7 +8,6 @@ use futures_core::Stream; use crate::{StdError, Url}; use crate::extension::{Extension, ExtensionFactories, ExtensionMetaInfo, LoadExtensionPromise}; use crate::extension::invoker_extension::proxy::InvokerProxy; -use crate::extension::registry_extension::proxy::RegistryProxy; use crate::params::extension_param::{ExtensionName, ExtensionType}; use crate::url::UrlParam; @@ -192,6 +191,10 @@ where T: Invoker + Send + 'static, T: Extension> { + fn name() -> String { + T::name() + } + fn extension_type() -> ExtensionType { ExtensionType::Invoker } diff --git a/dubbo/src/extension/mod.rs b/dubbo/src/extension/mod.rs index 296abfcf..d7020e64 100644 --- a/dubbo/src/extension/mod.rs +++ b/dubbo/src/extension/mod.rs @@ -285,7 +285,6 @@ impl ExtensionDirectoryCommander { #[allow(private_bounds)] pub async fn register(&self) -> Result<(), StdError> where - T: Extension, T: ExtensionMetaInfo, { let extension_name = T::name(); @@ -329,7 +328,6 @@ impl ExtensionDirectoryCommander { #[allow(private_bounds)] pub async fn remove(&self) -> Result<(), StdError> where - T: Extension, T: ExtensionMetaInfo, { let extension_name = T::name(); @@ -433,6 +431,7 @@ pub trait Extension { #[allow(private_bounds)] pub(crate) trait ExtensionMetaInfo { + fn name() -> String; fn extension_type() -> ExtensionType; fn extension_factory() -> ExtensionFactories; } diff --git a/dubbo/src/extension/registry_extension.rs b/dubbo/src/extension/registry_extension.rs index 44da815b..a4102265 100644 --- a/dubbo/src/extension/registry_extension.rs +++ b/dubbo/src/extension/registry_extension.rs @@ -71,6 +71,10 @@ where T: Registry + Send + Sync + 'static, T: Extension>, { + fn name() -> String { + T::name() + } + fn extension_type() -> ExtensionType { ExtensionType::Registry } diff --git a/examples/greeter/src/greeter/client.rs b/examples/greeter/src/greeter/client.rs index d2edae5f..b52abffe 100644 --- a/examples/greeter/src/greeter/client.rs +++ b/examples/greeter/src/greeter/client.rs @@ -24,6 +24,7 @@ use dubbo::codegen::*; use dubbo::extension; use futures_util::StreamExt; +use dubbo::extension::registry_extension::RegistryExtension; use protos::{greeter_client::GreeterClient, GreeterRequest}; use registry_nacos::NacosRegistry; @@ -31,7 +32,7 @@ use registry_nacos::NacosRegistry; async fn main() { dubbo::logger::init(); - let _ = extension::EXTENSIONS.register::().await; + let _ = extension::EXTENSIONS.register::>().await; let builder = ClientBuilder::new().with_registry("nacos://127.0.0.1:8848".parse().unwrap()); diff --git a/examples/greeter/src/greeter/server.rs b/examples/greeter/src/greeter/server.rs index 17a3ac49..7f4c99a6 100644 --- a/examples/greeter/src/greeter/server.rs +++ b/examples/greeter/src/greeter/server.rs @@ -33,6 +33,7 @@ use dubbo::{ }, Dubbo, }; +use dubbo::extension::registry_extension::RegistryExtension; use protos::{ greeter_server::{register_server, Greeter}, GreeterReply, GreeterRequest, @@ -60,7 +61,7 @@ async fn main() { Err(_err) => panic!("err: {:?}", _err), // response was droped }; - let _ = extension::EXTENSIONS.register::().await; + let _ = extension::EXTENSIONS.register::>().await; let mut f = Dubbo::new() .with_config(r) .add_registry("nacos://127.0.0.1:8848/");