Skip to content

serialize::Decodable decode() should return a IoResult/DecodeResult? #12292

Closed
@mneumann

Description

@mneumann

Decoding can fail in the same way as any IO operation or any read_xxx() function in trait Reader. So should the serialize::Decodable trait, no? Otherwise, we again depend on using task::try for decoding data structures.

My proposal is to change the signature of trait Decodable to something like:

pub type DecodeResult<T> = Result<T, &str>;

pub trait Decodable<D: Decoder> {
    fn decode(d: &mut D) -> DecodeResult<Self>;
}

Likewise, the trait serialize::Decoder must be changed to return DecodeResults as well.

This of course comes with a slight performance penalty in the non-error case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions