Skip to content

[Discussion] It's not necessary to use GAT in the Registry trait‘s definition #115

Closed
@onewe

Description

@onewe

Hi guys, I have been writting Nacos Registry module recently, I found that It's not necessary to use GAT in the Registry trait‘s definition, for the listener must be shareable and can't be removed ownership. so I think use Arc<dyn NotifyListener> is better.

我最近在写 nacos registry 模块, 我发现在 registry 定义中完全没必要使用 GAT, 因为 listener 肯定是一个共享的且不能被消费掉所有权的. 所以我觉得使用 Arc<dyn NotifyListener> 会更好点.

now

pub trait Registry {
    type NotifyListener;

    fn register(&mut self, url: Url) -> Result<(), crate::StdError>;
    fn unregister(&mut self, url: Url) -> Result<(), crate::StdError>;

    fn subscribe(&self, url: Url, listener: Self::NotifyListener) -> Result<(), crate::StdError>;
    fn unsubscribe(&self, url: Url, listener: Self::NotifyListener) -> Result<(), crate::StdError>;
}

change

pub type NotifyListener = Arc<dyn NotifyListener + Send + Sync + 'static>;
pub trait Registry {
    fn register(&mut self, url: Url) -> Result<(), crate::StdError>;
    fn unregister(&mut self, url: Url) -> Result<(), crate::StdError>;

    fn subscribe(&self, url: Url, listener: NotifyListener) -> Result<(), crate::StdError>;
    fn unsubscribe(&self, url: Url, listener: NotifyListener) -> Result<(), crate::StdError>;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions