Skip to content

Serialization errors can only be created from the Encoder/Decoder methods #15036

Closed
@huonw

Description

@huonw

There is no way for a custom generic Decodable/Encodable instance (compatible with #[deriving] other) to return a new error since it's completely generic, that is,

#[deriving(Decodable)]
struct Foo {
    x: Bar
}

struct Bar { y: int }

// E has to be that generic to work with the deriving above,
// but this means this impl cannot manually create new errors
// (e.g. if y is supposed to be an even number, there's no way
// to emit "error: found odd number".)
impl<E, D: Decoder<E>> Decodable<D, E> for Bar { ... }

It might be nice if there was a E: Error trait (or some such) that deriving used, which has some basic constructors.

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