• boonhet@sopuli.xyz
    link
    fedilink
    arrow-up
    12
    ·
    1 天前

    I find that the error messages themselves are a great tool for learning when it comes to Rust.

    • Kamikaze Rusher@lemmy.world
      link
      fedilink
      arrow-up
      5
      arrow-down
      1
      ·
      1 天前

      Eh, I’m not entirely sold on that idea.

      I think they do a good job of pointing out “this is a behavior/feature of Rust you need to understand.” However they can send you down the wrong path of correction.

      The compiler error mentioning static lifetime specifiers of &str demonstrates both. It indicates to the developer that ownership and scopes will play a significant role when defining and accessing data. The error though will guide them towards researching how to define static lifetimes and possibly believe that they will need to set this in their functions and structs. Each time you look at questions about this error in places like Stack Overflow with example code you’ll find suggested solutions explaining that a manually-defined static lifetime isn’t necessary to resolve the problem.

      • magic_lobster_party@fedia.io
        link
        fedilink
        arrow-up
        1
        ·
        12 小时前

        Static lifetimes confused me when I started learning rust. The error message guides the developer to the wrong direction.

        It took me a while to realize that just using Arc is sufficient in most of those cases.