07 Modules, Pub and Use | Rust Tutorials

preview_player
Показать описание
In this video I cover the Rust module system and how it interacts with public/private scope as well as importing our modules using the use keyword. Modules in Rust function very similarly to packages in Java or Python and modules in Javascript. They allows us to breakdown our code into more readable and more reusable pieces.

Find me elsewhere:

There are many ways to structure modules in Rust.
The main 3 ways are:

1. Using them inside a single file
2. Separating them into multiple files
3. Separating them into multiple folders

If you liked the video, please like, comment and subscribe!

The first way, all we need to do is use the mod keyword.
The second way, we no longer need the mod keyword, but we must name our file the same as our module.
Modules can be private (by default) or public using the pub keyword.

By using the use keyword, we bring modules into scope for our program to use.

If you have topics you want me to cover in future videos, leave a comment down below.

Рекомендации по теме
Комментарии
Автор

You probably don't know, but you're a hero. Really simple, well organized and clean tutorial. Thanks a lot for your work!

icarovieira
Автор

i applaud you compiling it first, getting an error, and then correcting it second.
this way the learning comes naturally as it is done step by step.
rust compiler is fantastic, so friendly to use.

michalbotor
Автор

Recently I was really confuse about modules and the use statement, even tho I'm an experienced programmer in other languages, and you made the best tutorial on this, 7 minutes and modules in Rust are crystal clear for me, thank you very much!

DHBids
Автор

Appreciate the short tutorial. Love how it's short and straightforward.

Urthor
Автор

Great concise tutorial! I'm learning rust with the rust book and I think your videos will help a lot to make me understand things better

JustLukeMinecraft
Автор

You have an excellent teaching technique, go straight to the point, I wish you could make more videos, your explanation is among the best quality up there, can you consider making a full Rust-project tutorial (maybe something easy for us to follow like creating CLI or something). Anyway, thank you again for your excellent tutorial. you've resolved the modules in Rust for me for sure.

Ghasakable
Автор

Wonderful! Simple and clean!! Keep it up!

parthiban
Автор

This video was so well done easy and clear. thank you so much!

datadoesdorian
Автор

Fantastic tutorial. Thank you for spending the time making it.

pheonex
Автор

so, the module is like a namespace in c++?

scshout
Автор

Very nice tutorial, it is concise and covers the scenario when the module becomes bigger. You save me time from going through the document. Thank you. Quick question, is it required to have the module file name as mod.rs ?

quangle
Автор

Nice tutorial, Thanks for making this.

ManasTunga
Автор

Thanks for the video! Organizing Rust modules might be tricky sometimes. May I ask what terminal are you using? It catched my attention the way you moved the split at the right bottom with your mouse.

Blure
Автор

Really nice way to explain this concept, my only take is the screen a bit cluttered, probably it will be confusing to a non-Linux WM user. Thanks a lot.

QQ-gntc
Автор

It isn't that complicated lol finally understood it thx

jctemp
Автор

Nice tutorial. Couple of pointers. As you are wizzing around (vim/neovim) it is so hard to see the directory structure of the project. This is more important on the last bit (which is probably more important as you scale up). Would have been good if some more time was spend showing multiple files/modules and modules from other creates of your own library, referencing and using them.

DineshPatel-fpwl
Автор

Thank you so much for this tutorial. This made no sense to me until now

buttforce
Автор

thanks so much!
i was really confused why i see both `mod` and `use` at the top of rust files.
but now i understand.
we have `mod` to bring modules to scope and we have `use` to grab things from module that we will frequently use.

michalbotor
Автор

I am probably not the first one to mention this but are you really using nano? On your projects? Kind of based

qsmfoui
Автор

Mind if I ask what operating system your using? Keep up the good work :)

thesmuggler