What are some tips and tricks and best practices with rust?
Also, I’m used to clearly defined classes and implementation files with C++. Are there any tips and tricks on that with Rust? I haven’t found any decent commentary/ documentation on figuring this out correctly with Rust. Yes, I know Rust is not an oop language, but I’m having issues creating clear separation of files so they don’t become a scrolling dungeon.
If it’s a full-fledged model data type, I tend to put it into an own file. It will usually get various trait implementations, like for converting from other data types, so that the separate file makes sense.
Often, there’s ‘auxiliary’ types, though. For example, I might have a function which takes a config object as parameter, which is only used there. Or it returns an enum of errors. In that case, I tend to define the types in the same file.
Generally, though, if you find yourself in a scrolling dungeon, that’s when you break things up. You don’t have to get things perfect from the start, because Rust’s module system is pretty good for splitting up files without a massive refactoring.