Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rm async_trait and add trait_variant #186

Closed
wants to merge 1 commit into from

Conversation

odysa
Copy link
Contributor

@odysa odysa commented Feb 3, 2024

Close #139
Use trait_variant::make to support async fn in pub traits. It creates 2 traits ---- LocalCatalog for single thread and Catalog with Send for multithreaded runtime.

pub trait Catalog: std::fmt::Debug {
/// see https://blog.rust-lang.org/2023/12/21/async-fn-rpit-in-traits.html
#[trait_variant::make(Catalog: Send)]
pub trait LocalCatalog: std::fmt::Debug {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we need this LocalCatalog variant? I think it would be enough to have a thread safe one.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the better approach would be like FileWriter trait, which adds Send for each return type:

pub trait Catalog: Debug + Send {
  fn list_namespace(&self, parent: Option<&NamespeceIdent>) -> impl Future<Output = 
Result<Vec<NamespaceIdent>>> + Send;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My goal was to minimize code changes as much as possible. There are 13 methods and 2 implementations of Catalog, while trait_variant is a one-line change. I personally prefer async fn over impl Future since it looks neater. But it is true that LocalCatalog is never used.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm hesitating adding this LocalCatalog trait. Also async fn seems much more concise to me. Maybe we should close this pr before finding a better approach?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rust-lang/impl-trait-utils#27

They are adding a rewrite feature to rewrite a trait instead of creating 2 variants. We can wait till it's done.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's great! Let's wait for this.

@liurenjie1024
Copy link
Collaborator

cc @odysa Should we close this?

@odysa
Copy link
Contributor Author

odysa commented Feb 19, 2024

@liurenjie1024 Yes, we can close this and reopen it after they release the rewrite feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

refactor: Remove async_trait in Catalog trait.
2 participants