How to transition from a C to a Rust mindset?

102 points thewrench56 40 comments

Hey!

I have been developing in (mainly) C and other languages for about a decade now and so seeing some of C's flaws being fixed by Rust, I was (and still am) curious about the language. So I tried it out on a couple of projects and the biggest issue I had which stopped me from trying and using Rust for years now was mainly the difference in paradigm. In C, I know exactly how to do what, what paradigm to use etc. The style people write C is roughly the same in all codebases and so I find it extremely easy to navigate new codebases. Rust, however, is a more complex language and as such reading Rust code (at least for me) is definitely harder because of its density and the many paradigm it allows for people.

I have a hard time understanding what paradigm is used when in Rust, when a struct should receive methods, when those methods should get their own trait, how I should use lifetimes (non-static ones), when should I use macros. I am quite well versed in OOP (Java and Python) and struct-based development (C), but when it comes to FP or Rust's struct system, I have trouble deciding what goes into a method, what goes into a function, what goes into a trait. Same applies about splitting code into separate files. Do I put code into mod.rs? Do I follow one struct one file? Is a trait a separate file?

So tldr, my issue isnt Rust's syntax or its API, but much rather I feel like it lacks a clear guide on paradigms. Is there such a guide? Or am I misguided in believing that there should be such a guide?

Thanks and cheers!