I've seen how Borrow
can help provide implementations for both &T
and T
but what tricks exist when T
is a higher-kinded type?:
use aws_smithy_runtime_api::client::result::SdkError;
impl<E, R> From<SdkError<E, R>> for Error
where
E: std::error::Error + Send + Sync + CreateUnhandledError + 'static,
R: std::fmt::Debug + Send + Sync + 'static,
{
fn from(err: SdkError<E, R>) -> Self {
do_conversion_stuff(&err)
}
}
impl<E, R> From<&SdkError<E, R>> for Error
where
E: std::error::Error + Send + Sync + CreateUnhandledError + 'static,
R: std::fmt::Debug + Send + Sync + 'static,
{
fn from(err: &SdkError<E, R>) -> Self {
do_conversion_stuff(err)
}
}
In this case I would think adding another generic, S: Borrow<SdkError<E, R>>
would work, but then there's no way to infer E
and R
.
So more broadly how can I avoid typing everything twice in this case?