Rust Generics

preview_player
Показать описание
An introduction to Rust Generics through example.

This Rust programming language tutorial series is aimed at easing your training step by step. Rust is a systems level language aimed at speed and safety and can be run cross-platform, including embedded systems and even the browser with WebAssembly (WASM)! I use the VS Code development environment to help you learn the core topics. Please join me on this journey with this fantastic new programming language.

Topics include coding basics, hello world, primitives, cargo, toml, rustup, arrays, borrowing, shadowing, string vs str, tuples, enumerations (enums), println and so much more...all free on youtube!
Рекомендации по теме
Комментарии
Автор

21:10 putting constraints at "struct" block level forces every "impl" blocks to apply these constraints but does not automatically apply them to "impl" blocks. This is more explicit this way and also allow "impl" blocks to apply more constraints than those specified on "struct" blocks.

julienduris
Автор

Coming from the JS battlefield, I had quite a hard time wrapping my head around all these concepts. You're doing a great job explaining them, thank you very much!

tobiasfuchsberger
Автор

Thanks Doug for your fantastic courses! Keep it coming. Very helpful to me.

annismonadjem
Автор

Your tutorials on Rust are so good that I click thumbs up before I watch the episode. ;)
I'm really surprised you have got so little views here, that a shame

haIk
Автор

Thanks for this tutorial, I managed to get it after watching it twice but I think it'd be easier to grasp if you used real world examples instead of arbitrary Struct, field and variable names like DougStruct, dougs_t, dougs_func etc. Sort of like what you did in the enum tutorial with the payment types, that me it way easier. Thanks again.

daviidon
Автор

What a beast! Saw 3 other channels but they would not address why we need to define generic type on functions. This did not only do that but went out of the way for ins and outs! Dayum! 🙌🙌

awais_korai
Автор

best video explaining generic type in 30 minutes

kevingzhang
Автор

Is there a way to tell the compiler to only allow some types of T to be available? Like in c++

template<typename T>
concept int_only = std::is_same_v<T, int32_t> || std::is_same_v<T, int64_t> || std::is_same_v<T, uint32_t> || std::is_same_v<T, uint64_t>; //do also for int16_t and int8_t

template<int_only T>
T add(T a, T b)
{
return a + b;
}

int main()
{

add(5.0f, 10.0f);
}

And whenever we'd pass a float or other type that is not allowed we'd get a compile error.

scshout
Автор

I wish you could make more advanced Rust videos, like error handling and testing! 🙏🏼🙌🏻

DSaad
Автор

I found myself thinking "we haven't covered options yet" for half a minute before I recognize that `OptionA(T)` isn't an `Option(T)` :)

busydying
Автор

Thanks Doug, you are a great teacher.
Love your content <3

PatentLobster
Автор

Hi Doug, can you please start rust coding projects

priyanshu
Автор

What if a struct already have a function with the same name as the trait function?

danvilela
Автор

One of the best and concise video i've seen so far about generics; Could u also make a video about Lifetimes, thank u very much!

Kserx.p
Автор

Doug, your videos are high quality and clear. Thanks for posting!

chistogo
Автор

7:07 made me laugh harder than it should have.

JordanIbanez
Автор

I finally got it!, I literally said Holy sh*t. You program to the trait unlocked generics for me, I was working backwards. The other statement that was an epiphany for me was "Lifetimes, it's all about the references. " THANKS SO MUCH !!

scottb
Автор

What did you do to have the type appear when you hover your mouse ? This doesn't happen in my VScode.

lolilollolilol
Автор

Fantastic job. I always confused myself with Where clause, type =, what a trait bound means. Now it's clear. Thanks sir.

TON-vzpe
Автор

Thanks for the informative video(s)! I especially enjoyed the Browser 3D series.


As for the last point, with being required to put where on the function, my guess is that the thought is to decouple the methods from the data. You could potentially make a number of methods on DougsStruct<T, U>, and instantiate many different types of T, U of it, and it'd be allowed as long as you don't actually use the log_something method. That's when the constraint kicks in.

aldergamestudio