Given this trait:
use std::io::{self, Read};
use std::fs::File;
pub trait Asset<D> {
fn load_data(path: &str) -> io::Result<D>
where
D: From<Vec<u8>>
{
let file = File::open(path)?;
let bytes_result: io::Result<Vec<u8>> = file.bytes().collect();
Ok(D::from(bytes_result?))
}
// many more methods...
}
the load_data method is only available when D implements From<Vec<u8>>, which makes sense. However, I would like every type implementing Asset<D> to have load_data, where if D implements From<Vec<u8>>, then it uses the default implementation. Otherwise, the type would have to implement load_data itself.