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

Is there a way to avoid Arg<T> #59

Closed
andrewgazelka opened this issue Jul 4, 2024 · 4 comments
Closed

Is there a way to avoid Arg<T> #59

andrewgazelka opened this issue Jul 4, 2024 · 4 comments

Comments

@andrewgazelka
Copy link

It is super annoying for auto completions to suggest divan get for literally everything.

/// Used by `#[divan::bench(args = ...)]` to enable polymorphism.
pub trait Arg<T> {
    fn get(self) -> T;
}

impl<T> Arg<T> for T {
    #[inline]
    fn get(self) -> T {
        self
    }
}
@dvdplm
Copy link

dvdplm commented Oct 3, 2024

I for one do not understand what your question is. Can you elaborate?

@andrewgazelka
Copy link
Author

andrewgazelka commented Oct 3, 2024

  • The code defines a trait Arg<T> with a single method get() -> T. This is a very generic trait that could potentially be used for any type.

  • The impl<T> Arg<T> for T { ... } block implements this trait for all types T. This means that every single type in your codebase now has a get() method available.

  • Modern IDEs use these trait implementations to provide auto-completion suggestions. Because get() is now technically available on every type, the IDE dutifully suggests it whenever you type . after any variable, regardless of its actual type.

Perhaps we could change the signature? Something like

pub trait Arg<T> {
    fn get(input: Self) -> T;
}

so we would have to call Arg::get(...) instead?

@dvdplm
Copy link

dvdplm commented Oct 4, 2024

I think you are talking about the private module's Arg trait, here.

@andrewgazelka
Copy link
Author

I think you are talking about the private module's Arg trait, here.

image

yes. However, IDEs will still recommend it.

@nvzqz nvzqz closed this as completed in cc31e54 Nov 1, 2024
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

No branches or pull requests

2 participants