Hey!

I’m a professional software engineer with several years of experience using Rust. Unfortunately I don’t really have the time to contribute to Lemmy directly myself, but I love teaching other people Rust so if:

  • You are curious about Rust and why you should even learn it
  • You are trying to learn Rust but maybe having a hard time
  • You are wondering where to start
  • You ran into some specific issue

… or anything to do with Rust really, then feel free to ask in the comments or shoot me a PM 🙂

  • SorteKanin@feddit.dkOP
    link
    fedilink
    English
    arrow-up
    3
    ·
    7 months ago

    do you have any thoughts to share on how Rust is best approached as a higher level / general purpose language? We discussed elsewhere in this comments section the idea that “over-optimising” memory management is unnecessary … that outside of hot loops you should just happily clone variables to make the borrow checker happy. Any other tricks or approaches you can think of?

    I would say make good use of the crates available. As said above, Rust as a language allows for very powerful abstractions. The language itself is quite low level, if you didn’t have any other code to use. But the standard library alone gives you a lot of tools. Add to that a host of practical crates that raise the abstraction level and you’ve got a very high-level experience.

    I can’t not share this meme btw. It’s obviously a joke but every joke has a bit of truth:

    For instance, you’ve got anyhow that allows for a bit of “quick and dirty” error handling via the ? operator. It’s useful for cases where you don’t care too much about what error happens, just that it happens. And when you get an error, you get a nice explanation of what happened (no 100 line exception stack trace with 1 needle in the haystack that maybe tells you what went wrong).

    There’s also serde (by the same author even) that allows for very easy serialization and deserialization, for instance into JSON or other formats.

    You could take a look at lib.rs to find more crates within a lot of different areas. It’s a bit more categorized and better sorted than crates.io. Learning the ecosystem of crates and what’s good for what is kind of a secondary thing to learn for Rust (or any language with a package ecosystem really) and it will take some trial and error probably.

    Does unsafe mode become a tool worth using, or is it not worth the hassle?

    No, unless you seriously need it and you definitely know what you’re doing, you don’t need it and you shouldn’t need it. If you’re reading stuff on this community, you don’t need unsafe. I’ve worked with Rust for many years and I’ve still only used unsafe in the areas where it’s really needed, like FFI (calling into C or C++ code). Perhaps with embedded programming you need it more, but most people don’t do much embedded.

    What about the Reference Counted pointer (smart pointer?) or Arc<Mutex>s (which I haven’t come to learn/understand) for handling memory management?

    You should definitely learn about Arc (Atomic Reference Counted pointer) and Mutex (mutual exclusion lock) - I believe the book has a chapter or something about them. They provide one way to achieve “shared” ownership across different threads and you’ll probably have lots of headaches if you don’t know about them.

    Are there good and nice crates or standard library tools that aren’t the most efficient or idiomatic but good for just getting stuff done?

    There’s some I mentioned above and for most major use cases, there are crates. Like axum for web servers as I mentioned above. Look at lib.rs I would say. It really depends on what specifically you want to do though.