It seems like a single blanket implementation for some trait prevents more implementations for the same trait with certain generic attributes even if theses attributes are explicitly excluded by trait bounds in the blanket implementation.
To me this feels like a shortcoming of the language that might be avoided. Should a Feature request be posted at the appropriate site ?
General example: using the New Type design pattern and implementing From / Into
you can do:
struct NewType(OldType);
impl<T: Into<OldType>> From<T> for NewType
where
OldType: From<T>,
{
fn from(value: T) -> Self {
NewType(value.into())
}
}
To implement all existing Generic variants of From
and Into
.
But then you can’t implement additional Generic Variants to this:
impl From<OtherType> for NewType { ... }
This results in
the trait `From<...>` is not implemented for `...`, which is required by `{...}: Into<_>`
More specific examples:
- trying to implement
into()
foru64
->f64
either directly (supposedly not a good idea) or via a NewType struct M64 (f64)
. - trying to implement
into()
for Error (NewError) to allow for doinglet e: NewError = "Message".into();
After a lot of research and discussions it seems clear that currently a blanket implementation prevents more implementations for the same Trait with different Generic attributes. IMHO this does not ask for any problems and should be allowed.