Kixiron / lasso

A fast, concurrent string interner
Apache License 2.0
137 stars 20 forks source link

`Default` trait is not implemented for rodeo with spur types other than `Spur` #26

Open lo48576 opened 3 years ago

lo48576 commented 3 years ago

I tried this code

#[derive(Default)]
struct Foo {
    strings: Rodeo<lasso::MiniSpur>,
}

I expected this to happen

The code compiles.

Instead this happened

This does not compile. Compiler says error[E0277]: the trait bound `lasso::Rodeo<lasso::MiniSpur>: std::default::Default` is not satisfied.

Meta

Lasso version: 0.5.0

Rustc version: 1.52.0

> rustc -Vv
rustc 1.52.0 (88f19c6da 2021-05-03)
binary: rustc
commit-hash: 88f19c6dab716c6281af7602e30f413e809c5974
commit-date: 2021-05-03
host: x86_64-unknown-linux-gnu
release: 1.52.0
LLVM version: 12.0.0

Additional context

impl Default for Rodeo<Spur, RandomState> redirects to Self::new(), and Self::new() is implemented for any Rodeo<K, RandomState> where K: Key. Is there any reason not to implement impl<K: Key> Default for Rodeo<K, RandomState>?

Kixiron commented 3 years ago

That's a good question, thanks! Originally the concrete types for Default were made with the idea that "Spur is the default type, so that's what Default should make", but I think I just forgot to update the definition of Default when I messed with new(). It still does have the downside that it no longer allows Rodeo::default() to "just work" due to inference, but that probably doesn't matter very much