doctorn / obake

Versioned data-structures for Rust
Apache License 2.0
203 stars 8 forks source link

fix: Use concrete Versioned type in From impl #9

Closed samvrlewis closed 1 year ago

samvrlewis commented 1 year ago

Changes the From impl to use the Versioned type rather than the associated type (through obake::AnyVersion). This shouldn't change anything functionally but fixes an issue we were seeing where the obake impl From<foo::Foo_v0_1_0> for <foo::Foo_v0_1_0 as obake::Versioned>::Versioned impl was conflicting with other generic impls.

You can see a small reproducible example of this issue here: https://github.com/goodSyntax808/obake-example-issue which gives the following error when trying to compile:

error[E0119]: conflicting implementations of trait `std::convert::From<foo::Foo_v0_1_0>` for type `Batz`
  --> bar\src\lib.rs:7:1
   |
7  | / impl<T> From<T> for Batz
8  | | where
9  | |     T: Into<Cow<'static, str>>,
10 | | {
...  |
13 | |     }
14 | | }
   | |_^
   |
   = note: conflicting implementation in crate `foo`:
           - impl From<foo::Foo_v0_1_0> for <foo::Foo_v0_1_0 as obake::Versioned>::Versioned;

I believe this occurs because impl From<foo::Foo_v0_1_0> for <foo::Foo_v0_1_0 as obake::Versioned>::Versioned can technically be the same as impl<T> From<T> for Batz if <foo::Foo_v0_1_0 as obake::Versioned>::Versioned implemented Into<Cow<'static, str>>. Using the actual type, rather than the associated type, helps avoid this problem.

doctorn commented 1 year ago

This is awesome -- thank you!

samvrlewis commented 1 year ago

Thanks for the super quick turn around on this (and for pushing out a new version to crates.io already)!