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

Feature request: common Error enum for read/write #211

Open
ngeor opened this issue Oct 30, 2021 · 0 comments
Open

Feature request: common Error enum for read/write #211

ngeor opened this issue Oct 30, 2021 · 0 comments
Assignees

Comments

@ngeor
Copy link

ngeor commented Oct 30, 2021

This can be useful for code that uses both xml::reader::Error and xml::writer::Error (e.g. a function that processes an input XML file and outputs a different XML file). In that case, the code needs to handle two different error structures. The workaround is relatively easy, I can write my own error enum that wraps both read/write errors, together with the From trait implementations. This way, my code can use the ? operator on both xml::reader and xml::writer code.

Maybe this should be provided out of the box by the xml-rs library? Otherwise everyone who is writing an xml transformation function will have to re-invent it.

#[derive(Debug)]
pub enum XmlError {
    ReadError(xml::reader::Error),
    WriterError(xml::writer::Error)
}

impl From<xml::reader::Error> for XmlError {
    fn from(value: xml::reader::Error) -> Self {
        Self::ReadError(value)
    }
}

impl From<xml::writer::Error> for XmlError {
    fn from(value: xml::writer::Error) -> Self {
        Self::WriterError(value)
    }
}
@kornelski kornelski self-assigned this May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants