Why does my trait need a lifetime parameter?
问题 Being a Rust newbie, I probably somewhat naively started with this: ... pub trait Decode<T> { fn decode_from<R: io::Read + ?Sized>(&mut self, stream: &mut R) -> T; } pub struct MQTTFrame<'a> { pub payload: &'a Vec<u8>, } pub struct MQTTFrameDecoder<'a> { pub payload: &'a mut Vec<u8>, } impl<'a> Decode<MQTTFrame<'a>> for MQTTFrameDecoder<'a> { fn decode_from<R: io::Read + ?Sized>(&mut self, stream: &mut R) -> MQTTFrame<'a> { stream.read(&mut self.payload); MQTTFrame{ payload: self.payload } }