Closed guyru closed 1 year ago
The solution is to define a supertrait
trait MyDigest: DynDigest + Write {}
impl<T: DynDigest + Write> MyDigest for T {}
and have the Box refer to it:
let mut hasher: Box<dyn MyDigest> = Box::new(Md5::default());
Yeah, the issue is that currently we are not allowed to write impls like this:
impl<T: DynDigest> std::io::Write for T { .. }
And there is a good reason for that, since such impl would conflict with impls on the wrapper types.
Ideally, Rust would allow you to write Box<dyn DynDigest + io::Write>
, but alas I don't think this feature will be implemented and stabilized in the near future.
Hi,
It seems like you can't use std::io::copy when working with DynDigest objects. For example:
will fail to compile and complain about