• Lightfire228@pawb.social
    link
    fedilink
    arrow-up
    5
    ·
    edit-2
    22 hours ago

    To explain

    There are 2 Error struct / enum declarations, probably in separate files

    To the ?, they are different types and cannot be converted from one to the other (because they are two disparate structs that happen to have the same name, but can have different bodies)

    To fix this

    You can either use .some_func_result().map_err(|err| /* conversion here/*)?; +

    Or you can impl From<Error1> for Error2

    And you should also name it ThingError, so you can visually differentiate the two


    + There are like 10 different mapping functions, depending on if you’re using an option or a result

    I never remember which one specifically i need, (unwrap_or, map_or, map_or_else, ok, ok_or)

    I usually just hunt through the auto complete list until i find the function signature that gives me what i need

  • Alk@sh.itjust.works
    link
    fedilink
    arrow-up
    23
    ·
    1 day ago

    Copied from the other repost:

    Have you erased the continuation of the message that is saying something about “similar names, but are actually two distinct types”?

    It is a common error if you have two dependecies that export the same third dependency and your code makes an assumption that the versions of the third dep match.

    All other languages either straight-up don’t support multiple versions of the same dep, or throw random errors at runtime. So this message is a consequence of rust supporting things that other langs only dream of.

    • bratorange@feddit.orgOP
      link
      fedilink
      arrow-up
      2
      ·
      13 hours ago

      Hey thank you guys for your attempt to help, although I have already figured it out. I feel this is not the place for support requests, and my intention was rather just to share this funny error statement.

  • Ephera@lemmy.ml
    link
    fedilink
    English
    arrow-up
    11
    ·
    1 day ago

    If you run a build command on the CLI, it should tell you the full type names…