Skip to content

Commit

Permalink
remove Extension constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
onewe committed May 10, 2024
1 parent 7d0ee36 commit 1064a1d
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
5 changes: 4 additions & 1 deletion dubbo/src/extension/invoker_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -192,6 +191,10 @@ where
T: Invoker + Send + 'static,
T: Extension<Target= Box<dyn Invoker + Send + 'static>>
{
fn name() -> String {
T::name()
}

fn extension_type() -> ExtensionType {
ExtensionType::Invoker
}
Expand Down
3 changes: 1 addition & 2 deletions dubbo/src/extension/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ impl ExtensionDirectoryCommander {
#[allow(private_bounds)]
pub async fn register<T>(&self) -> Result<(), StdError>
where
T: Extension,
T: ExtensionMetaInfo,
{
let extension_name = T::name();
Expand Down Expand Up @@ -329,7 +328,6 @@ impl ExtensionDirectoryCommander {
#[allow(private_bounds)]
pub async fn remove<T>(&self) -> Result<(), StdError>
where
T: Extension,
T: ExtensionMetaInfo,
{
let extension_name = T::name();
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions dubbo/src/extension/registry_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ where
T: Registry + Send + Sync + 'static,
T: Extension<Target = Box<dyn Registry + Send + Sync + 'static>>,
{
fn name() -> String {
T::name()
}

fn extension_type() -> ExtensionType {
ExtensionType::Registry
}
Expand Down
3 changes: 2 additions & 1 deletion examples/greeter/src/greeter/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ 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;

#[tokio::main]
async fn main() {
dubbo::logger::init();

let _ = extension::EXTENSIONS.register::<NacosRegistry>().await;
let _ = extension::EXTENSIONS.register::<RegistryExtension<NacosRegistry>>().await;

let builder = ClientBuilder::new().with_registry("nacos://127.0.0.1:8848".parse().unwrap());

Expand Down
3 changes: 2 additions & 1 deletion examples/greeter/src/greeter/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use dubbo::{
},
Dubbo,
};
use dubbo::extension::registry_extension::RegistryExtension;
use protos::{
greeter_server::{register_server, Greeter},
GreeterReply, GreeterRequest,
Expand Down Expand Up @@ -60,7 +61,7 @@ async fn main() {
Err(_err) => panic!("err: {:?}", _err), // response was droped
};

let _ = extension::EXTENSIONS.register::<NacosRegistry>().await;
let _ = extension::EXTENSIONS.register::<RegistryExtension<NacosRegistry>>().await;
let mut f = Dubbo::new()
.with_config(r)
.add_registry("nacos://127.0.0.1:8848/");
Expand Down

0 comments on commit 1064a1d

Please sign in to comment.