I have tried to implement a generic deserialization like the following:
pub trait Decodable {
type Output;
fn decode(value: &Encoded) -> Result<Self::Output>;
}
impl<T: Decodable> Decodable for Vec<T> {
type Output = Vec<T>;
fn decode(value: &Encoded) -> Result<Self::Output> {
let mut result = Vec::with_capacity(value.len());
for item in list {
result.push(decode::<T>(item)?);
}
Ok(result) // expected type parameter `T`, found associated type
}
}
fn decode<T: Decodable>(value: &Encoded) -> Result<T::Output> {
// ...
}
But with the solution above I get an error at compile time:
expected type parameter
T
, found associated type
How do I resolve this issue?