divan icon indicating copy to clipboard operation
divan copied to clipboard

Is there a way to avoid `Arg<T>`

Open andrewgazelka opened this issue 1 year ago • 4 comments

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
    }
}

andrewgazelka avatar Jul 04 '24 23:07 andrewgazelka

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

dvdplm avatar Oct 03 '24 09:10 dvdplm

  • 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?

andrewgazelka avatar Oct 03 '24 19:10 andrewgazelka

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

dvdplm avatar Oct 04 '24 08:10 dvdplm

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

image

yes. However, IDEs will still recommend it.

andrewgazelka avatar Oct 04 '24 21:10 andrewgazelka

This is now fixed in v0.1.16.

nvzqz avatar Nov 26 '24 02:11 nvzqz