Skip to content

Type the error in the traits BytesEncode and BytesDecode #165

Open
@irevoire

Description

@irevoire

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>;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestfeedbackA feedback from a user

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions