9 Rust Best Practices - Utils, Examples, Tests (Part 2/3)

  Рет қаралды 4,452

Jeremy Chone

Jeremy Chone

Күн бұрын

Пікірлер: 18
@jeffg4686
@jeffg4686 4 ай бұрын
Something that I get confused on sometimes is when to go with a module versus another crate in the workspace. Is it just that modules evolved first? In a project like C#, I'd just create another assembly, which would pretty much equate to another crate in rust. I actually made very little use of creating custom namespaces within an assembly when coding C#. I see a mod kind of like a namespace - that's what it is mostly, right? I see partitioning for me - regular project specific work (not APIs) as just being separates crates in the workspace. Would you tend to go with a "moduleless" solution (not sure if that's the right word because I guess there's always the initial module of the program. But when you set a dependency to another crate in your project, you don't need modules - just the 'use' import. Anyways, I just wanted to see if people are going with moduleless now? I'm pretty sure they should have gone with namespace instead of mod..., but I digress. I know they wanted it to be "different"
@JeremyChone
@JeremyChone 4 ай бұрын
First, if you're not sure, I would start with a single crate. Organize concerns into modules and module hierarchy if needed. Then, when the code base approaches 5k LOC (not a perfect metric, but just for the discussion), I think splitting the application into sub-crates makes a lot of sense. Crates have a few more constraints since you cannot have cyclic dependencies. However, this often forces you to have the right level of sub-crates and not go overboard. If our "key modules" are well-designed and independent (have their own errors, etc.), they are typically relatively simple to split out. So, I would say start with modules, and then, when it becomes obvious that multiple crates will help the code grow, go in that direction.
@notwheeliesure
@notwheeliesure 26 күн бұрын
How are you getting region folding in vscode? It doesn't seem to be a default feature. FYI, I am using the official rust-analyzer extension.
@meowsqueak
@meowsqueak 4 ай бұрын
6:26 Why “lib-utils/”, “lib-core/”, etc and not “lib/utils/” or “lib/core/” for sub crates, to keep it similar to Rust’s name-spacing with mods, rather than by prefix (C style)? Hmm, is “lib/“ a reserved directory name in a workspace?
@JeremyChone
@JeremyChone 4 ай бұрын
@@meowsqueak Because, when we import it, we know that lib_... is ours and not an external trait. Now, this is just a personal preference. Dev should use what works for them and their team.
@meowsqueak
@meowsqueak 4 ай бұрын
⁠ah, right, so the prefix “lib-“ is the thing you see and identity as “that’s our crate”? So could be anything really, as you say. Handy! I’m thinking I might use “local-“.
@meowsqueak
@meowsqueak 4 ай бұрын
This makes me think that crates should be namespaced in general :-/
@JeremyChone
@JeremyChone 4 ай бұрын
​@@meowsqueak Yes, exactly. Could be mystuff-, I just chose lib because it was simple and fitting. Sometimes for other types of libs, I could have worker-... for the worker type of services. In awesomeapp, I have them in lib-worker, but that should be split away. More on that later. Good question though.
@JeremyChone
@JeremyChone 4 ай бұрын
@@meowsqueak I went back and forth on the top crates folder and saw some other libs/frameworks using "crates/." I found that kind of clear, even if it might sound odd. In doubt, I always opt for clarity.
@RoamingAdhocrat
@RoamingAdhocrat 4 ай бұрын
Kevlin Henney has shamed me out of naming anything "util"
@JeremyChone
@JeremyChone 4 ай бұрын
Ho, yes this is another debate. I do not have strong opinions either way, and I can see the argument to go with “util.”
@JeremyChone
@JeremyChone 4 ай бұрын
By the way, I'm not saying there couldn't be another perspective, but in this case, I decided to go with "utils" because this approach involves a set of independent elements without even a common entry point or error, for example. So, my current rule of thumb is that when a module is a bag of related but independent constructs, using the plural might be warranted. However, when something has its own purpose besides grouping a set of things, the singular might be better. Now, it's tricky because sometimes it's not as clear-cut. But again, these things are highly subjective. I would recommend going with whatever the team decides, and if a team member feels strongly about one way, let it be. Consistency is more important.
@solmateusbraga
@solmateusbraga 4 ай бұрын
Imma use "stuff"
@damianradinoiu4314
@damianradinoiu4314 3 ай бұрын
your part 3 video got deleted from KZbin before I got to watch it :(
@JeremyChone
@JeremyChone 3 ай бұрын
I did not do it yet, I will release within a week,or so.
@damianradinoiu4314
@damianradinoiu4314 3 ай бұрын
@@JeremyChone oh.. then it must have been my "Deja Vu"... I discovered your channel recently and I like it, sorry for the misunderstanding
@JeremyChone
@JeremyChone 3 ай бұрын
Ho, no, I am the one late. I should have made the series back to back.
@irlshrek
@irlshrek 4 ай бұрын
LETS GOOOOOOOOOOO
Rust genai - ModelMapper (Model Aliasing) - Code Demo
8:07
Jeremy Chone
Рет қаралды 1,3 М.
5 Steps to Learn Rust Programming
25:06
Jeremy Chone
Рет қаралды 9 М.
My scorpion was taken away from me 😢
00:55
TyphoonFast 5
Рет қаралды 2,7 МЛН
Что-что Мурсдей говорит? 💭 #симбочка #симба #мурсдей
00:19
9 Rust Best Practices - Async, Project Files, Versioning (Part 3/3)
12:52
Rust Ollama By Examples - 4 Chapters (Full Tutorial - Rust AI)
1:00:42
A Simpler Way to See Results
19:17
Logan Smith
Рет қаралды 117 М.
9 Rust Best Practices with Real Lib (part 1/3)
27:11
Jeremy Chone
Рет қаралды 12 М.
Rust Error Handling - Best Practices
21:33
Jeremy Chone
Рет қаралды 26 М.
From Zero to Async in Embedded Rust
1:02:06
The Rusty Bits
Рет қаралды 28 М.
Use Arc Instead of Vec
15:21
Logan Smith
Рет қаралды 155 М.
Parse Rust CLI Args With Clap 🦀 Rust Tutorial
54:03
Trevor Sullivan
Рет қаралды 13 М.
Implementing and Optimizing a Wordle Solver in Rust
6:08:52
Jon Gjengset
Рет қаралды 137 М.
You Should Really Know These Traits in Rust
18:36
Oliver Jumpertz
Рет қаралды 17 М.
My scorpion was taken away from me 😢
00:55
TyphoonFast 5
Рет қаралды 2,7 МЛН