Skip to content

API: Return a proper error type instead of String #1053

Open
@LunarLambda

Description

@LunarLambda

String does not implement std::error::Error, making interoperability with error-handling crates such as failure or anyhow much more difficult.

SDL2 already has an Error enum, with variant SdlError(String), we just need to use it.

Right now, to use anyhow's Context extension, for example, one needs to do the following:

use anyhow::{Context, Result}

fn main() -> Result<()> {
    let sdl = sdl2::init().map_err(sdl2::Error::SdlError).context("Failed to initialize SDL lbirary.")?;
}

unrelated, but why is render::SdlError a seperate newtype around a String, independent from the above mentioned Error enum (which has an un-newtyped variant of the same name)? It is only used by TargetRenderError.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions