I want to learn Rust. There are so many resources available and I am unsure which one to go for, and if there are any tips on getting started?

I am a software developer by trade

Edit: Thanks for all the great replies!

  • StrikeForceZero@programming.dev
    link
    fedilink
    arrow-up
    74
    ·
    2 months ago

    As a wise person once told the Internet, don’t worry about picking the best one. But if you really had to pick one just start with the rust book. https://doc.rust-lang.org/book/ I would suggest to just dive in with a specific need you want to solve and instead of using your language of choice just use rust and look up stuff as you go. Hands on learning is usually the best learning. The only thing you need to “learn” is how to follow the ownership/borrowing paradigm that rust brings to the table.

  • Solemarc@lemmy.world
    link
    fedilink
    arrow-up
    18
    ·
    2 months ago

    IMO the best way to start in a new language is to rewrite some of your previous projects in that language.

    I generally start out by rewriting a couple simple 1-3 function console apps, basic leet code stuff like; palindrome, fizzbuzz, reverse an array in place, etc, and some simple unit tests for them. Then I go ahead and rewrite some of my previous projects or uni assignments in that language.

    At that point I generally have a good understanding of basics and have an idea of how to approach a new project. When I got to this point in rust I then started on threading, async, why it’s easy to return a String and an ordeal to return &str, etc.

    • hector@sh.itjust.works
      link
      fedilink
      arrow-up
      4
      arrow-down
      5
      ·
      2 months ago

      Please, don’t ever use async Rust lol :( it’s so terrible to work with closure recapture. There’s really one way of structuring your code to keep the borrow checker happy and I haven’t yet found it in my projects lol.

      • FizzyOrange@programming.dev
        link
        fedilink
        arrow-up
        6
        arrow-down
        1
        ·
        2 months ago

        Yeah I would also recommend avoiding async Rust as much as possible. There’s really only a small number of situations where you need it - WASM, embedded (Embassy), and unfortunately most of the web ecosystem forces you to use it even if it isn’t necessary for 99% of people.

        Sync Rust - even multithreaded - is absolutely fantastic at protecting you from mistakes & giving an “if it compiles it works” experience. Async Rust on the other hand is full of surprising and difficult to debug footguns.

  • thefatfrog@lemmy.world
    link
    fedilink
    arrow-up
    10
    ·
    2 months ago

    If you are looking to create a web service, I can suggest the zero2prod book. That’s how I learned rust and loved the process. I was also already a seasoned developer before taking interest into rust

  • InternetCitizen2@lemmy.world
    link
    fedilink
    arrow-up
    9
    ·
    2 months ago

    A big part is kinda just doing it. I am trying to learn and it is kinda wild. I am currently working a warehouse job so it is hard to find the time. Try and go back and implement some of your favorite homework assignments in Rust.

    I think a hard part of Rust is the mind shift. It just feels very different from anything else I have tired. I am doing some encapsulation for my learning, but it is not clear where to read about it and there are few examples out there.

  • tiredofsametab@fedia.io
    link
    fedilink
    arrow-up
    8
    ·
    2 months ago

    I agree with the others who say to start with The Book – https://doc.rust-lang.org/book/

    From there, start trying to create small things that you might want or need to do (parsing JSON is something that I needed to do and I started there).

    From there, you will learn to fight the borrow checker and start to feel how rust is working. This will be annoying at first, but get better over time (at least in older versions of Rust; I haven’t used it in a while so it may be different now).

    • Iapar@feddit.org
      link
      fedilink
      arrow-up
      1
      arrow-down
      1
      ·
      2 months ago

      What is the borrow checker and why are people so frustrated by it?

      • tiredofsametab@fedia.io
        link
        fedilink
        arrow-up
        3
        ·
        2 months ago

        Very TL;DR version: a variable has an owner. If you pass it off to another function, you no longer own it and can’t use it until/unless it gives the variable back. Rust can be really strict on making sure you aren’t trying to use something you don’t own at that time. The documentation explains it better than this (and I wrote a longer post but accidentally closed the window and lost it). See also mutability and lifetimes for some pain points people might not be used to.

  • Hawk@lemmynsfw.com
    link
    fedilink
    arrow-up
    5
    arrow-down
    1
    ·
    2 months ago

    The book is really good and offers a snapshot of those inner workings of the language.

    For using it, LLMs (open weight and otherwise) perform very well and may fill the gap.

  • DumbAceDragon@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    3
    ·
    2 months ago

    People already suggested it, but rustlings is awesome.

    One thing I like to do is think of something I often do in another language, then Google how to do it in rust, i.e. dynamic dispatch. The way rust does it with traits is really interesting.