duesee / imap-codec

Rock-solid and complete codec for IMAP
Apache License 2.0
35 stars 13 forks source link

Decoder::decode_static does not return 'static error #355

Closed jakoschiko closed 11 months ago

jakoschiko commented 11 months ago

This is the current signature of Decoder::decode_static:

fn decode_static<'a>(
    &self,
    input: &'a [u8],
) -> Result<(&'a [u8], Self::Message<'static>), Self::Error<'a>>
where
    Self::Message<'a>: IntoBoundedStatic<Static = Self::Message<'static>>

IMO it makes more sense to return Self::Error<'static> here because I think the default use case of this method is "I don't care about allocation, just gimme 'static". This would require to add the bound Self::Error<'a>: IntoBoundedStatic<Static = Self::Error<'static>>. This should be possible because as far as I know all actual error types derive ToStatic.

Alternatives:

duesee commented 11 months ago

Good catch! Yeah, I think it should be Error<'static>. Alternative 4: Error could also be owned. In the end, it's only the tag that introduces the lifetime?