Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type the error in the traits BytesEncode and BytesDecode #165

Open
irevoire opened this issue Feb 20, 2023 · 0 comments · May be fixed by #166
Open

Type the error in the traits BytesEncode and BytesDecode #165

irevoire opened this issue Feb 20, 2023 · 0 comments · May be fixed by #166
Labels
enhancement New feature or request feedback A feedback from a user
Milestone

Comments

@irevoire
Copy link
Member

It's strange not to be able to return a typed error with the BytesEncode and BytesDecode traits.

It would be nice to have something like that;

/// A trait that represents an encoding structure.
pub trait BytesEncode<'a> {
    type EItem: ?Sized + 'a;
    type Err;

    fn bytes_encode(item: &'a Self::EItem) -> Result<Cow<'a, [u8]>, Self::Err>;
}

/// A trait that represents a decoding structure.
pub trait BytesDecode<'a> {
    type DItem: 'a;
    type Err;

    fn bytes_decode(bytes: &'a [u8]) -> Result<Self::DItem, Self::Err>;
}
@irevoire irevoire added enhancement New feature or request feedback A feedback from a user labels Feb 20, 2023
@Kerollmops Kerollmops added this to the v0.20.0 milestone Mar 5, 2023
@Kerollmops Kerollmops changed the title v0.20: Type the error in the traits BytesEncode and BytesDecode Type the error in the traits BytesEncode and BytesDecode Mar 5, 2023
@Kerollmops Kerollmops modified the milestones: v0.20.0, v0.21.0 Feb 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feedback A feedback from a user
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants