• calcopiritus@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    3 days ago

    In my case, I don’t usually encounter cases where I can’t just ?. But when I do, just make an error enum (kinda like thiserror) that encapsulates the possible errors + possibly adds more.

    On the call site, just convert to string if I don’t care about specifics (anyhow-style).

    I don’t find this much painful.

    Concise: not much on the declaration side, since you have to create an entire enum for each function in worst-case scenario. But on code side, it’s just .map_err(MyError)?.

    Type-safe: can’t beat errors as enum values wrapped in Result.

    Composable: i don’t think you can beat rust enums in composability.

    I don’t use anyhow/thiserror, so I’m not sure. But I believe thiserror fixes the conciseness issue for this.