Rust Generics

  Рет қаралды 21,231

Doug Milford

Doug Milford

Күн бұрын

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!

Пікірлер: 57
@awais_korai
@awais_korai Жыл бұрын
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! 🙌🙌
@scottb4029
@scottb4029 9 ай бұрын
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 !!
@julienduris8326
@julienduris8326 2 жыл бұрын
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.
@karelhrkal8753
@karelhrkal8753 Жыл бұрын
This definitely is one of those moment where the Rust compiler seems more autistic than it needs to be, but it makes sense once you realize Rust is always trying to keep relevant things together. Want to use a method in the implementation? It better be in the constraints of the implementation, and not somewhere else! (Even if that "somewhere else" is in the struct that the impl is implementing).
@haI9k
@haI9k 3 жыл бұрын
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
@TON-vz3pe
@TON-vz3pe Жыл бұрын
Fantastic job. I always confused myself with Where clause, type = , what a trait bound means. Now it's clear. Thanks sir.
@tobiasfuchsberger900
@tobiasfuchsberger900 4 жыл бұрын
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!
@dougmilford7814
@dougmilford7814 4 жыл бұрын
Hey, I appreciate the compliment :)
@klimentdukovski
@klimentdukovski Жыл бұрын
Your videos are by far the best ones on Rust and I've watched a lot of them. Thank you, sir 🙏
@annismonadjem6901
@annismonadjem6901 4 жыл бұрын
Thanks Doug for your fantastic courses! Keep it coming. Very helpful to me.
@dougmilford7814
@dougmilford7814 4 жыл бұрын
From your previous comment on the Structs and Traits video you had asked if I could make a Generics video. I was going to tell you that the Generics video you requested was up, but you beat me to the punch! Ha, ha, ha... I'm glad you're enjoying them.
@kennethmarete5329
@kennethmarete5329 Жыл бұрын
Awesome content, great teacher, articulate lessons, great tutorial. The best I have seen so far. Thanks Doug Milford
@kevingzhang
@kevingzhang 4 жыл бұрын
best video explaining generic type in 30 minutes
@dougmilford7814
@dougmilford7814 4 жыл бұрын
Ah, thanks!
@DSaad
@DSaad 7 ай бұрын
I wish you could make more advanced Rust videos, like error handling and testing! 🙏🏼🙌🏻
@chistogo3
@chistogo3 3 жыл бұрын
Doug, your videos are high quality and clear. Thanks for posting!
@busydying
@busydying 4 жыл бұрын
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)` :)
@PatentLobster
@PatentLobster 3 жыл бұрын
Thanks Doug, you are a great teacher. Love your content
@GlobalYoung7
@GlobalYoung7 2 жыл бұрын
Thanks Doug . Very helpful to me.❤️👍
@CalangoBit
@CalangoBit 3 жыл бұрын
20:14 Using println!("{}", result2); expected "18-first-second", but the result presented was i32-first-second. Thanks so much for the videos!!!
@bobgodwinx
@bobgodwinx 2 жыл бұрын
Great video!
@ChinchillaDave
@ChinchillaDave 3 жыл бұрын
Doug you're awesome.
@MrGreen-kq4ds
@MrGreen-kq4ds 3 жыл бұрын
this is gold, thanks!
@Kserx.p
@Kserx.p 4 жыл бұрын
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!
@dougmilford7814
@dougmilford7814 4 жыл бұрын
Thanks! I'm currently finishing up the Lifetimes video as we speak. I'm hoping to have it out by the end of this weekend, but no promises.
@dougmilford7814
@dougmilford7814 4 жыл бұрын
I published the video on Lifetimes. I hope it helps!
@glennsingh354
@glennsingh354 3 жыл бұрын
Subscribing your channel today ❤️ Thanks for such awesome clips. I am expecting some tutorials on diesel queries with postgresql. Hope.
@osxxii2931
@osxxii2931 3 жыл бұрын
Thank you so much! Your Rust series is just awesome, clear and concise!
@Jordan4Ibanez
@Jordan4Ibanez 3 жыл бұрын
7:07 made me laugh harder than it should have.
@warrenbuckley3267
@warrenbuckley3267 3 жыл бұрын
Doug there are fantastics videos, I hope you're still planning on making these. I would really like to see one on iterators.
@aldergamestudio3016
@aldergamestudio3016 4 жыл бұрын
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, 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.
@dougmilford7814
@dougmilford7814 4 жыл бұрын
Yeah, it looks like you're correct. You can put the where clause on each method as well, not just on the impl block. When I do that, the compiler is smart enough to only give a compile error if I call specific methods. Interesting!
@nickschmitt8594
@nickschmitt8594 3 жыл бұрын
You're a god.
@daviidon
@daviidon 3 жыл бұрын
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.
@dougmilford7814
@dougmilford7814 3 жыл бұрын
Yeah, point taken. Often it's easier to learn from real examples. I'll keep that in mind for future videos.
@DoisKoh
@DoisKoh 2 жыл бұрын
@@dougmilford7814 This is already extremely useful though, thanks.
@danvilela
@danvilela 3 жыл бұрын
This is awesome!!!
@ati43888
@ati43888 Жыл бұрын
Thank you so much
@LeoUnglaub
@LeoUnglaub 4 жыл бұрын
Great Video, thanks!
@dougmilford7814
@dougmilford7814 4 жыл бұрын
Yep yep, you're welcome :)
@ashwanisingh3049
@ashwanisingh3049 3 жыл бұрын
Very helpful 👍 Really Thanks for this. I request you please make some tutorial on rust with diesel orm . Not understanding diesel.
@tech_niks
@tech_niks 3 жыл бұрын
Each and every video is awesome ✨...but only thing that i struggle is sequences to watch...if video title in Sequences ....its easy to understand...else...it help a lot myself...to start with rust...thanks🥳
4 жыл бұрын
Wonderful video!
@dougmilford7814
@dougmilford7814 4 жыл бұрын
Thank, man! I appreciate the compliment :)
@danvilela
@danvilela 3 жыл бұрын
What if a struct already have a function with the same name as the trait function?
@coreyhartman4510
@coreyhartman4510 4 жыл бұрын
excellent video.
@dougmilford7814
@dougmilford7814 4 жыл бұрын
Hey, thanks! Glad you liked it :)
@priyanshu4016
@priyanshu4016 Жыл бұрын
Hi Doug , can you please start rust coding projects
@sc5shout
@sc5shout 2 жыл бұрын
Is there a way to tell the compiler to only allow some types of T to be available? Like in c++ template concept int_only = std::is_same_v || std::is_same_v || std::is_same_v || std::is_same_v; //do also for int16_t and int8_t template T add(T a, T b) { return a + b; } int main() { //ERRORRRRR!!! 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.
@sc5shout
@sc5shout 2 жыл бұрын
What if few structs and functions need exactly the same constraints? Is there a way to name, like, 5 constraints and use only 1 name to get them all?
@lolilollolilol7773
@lolilollolilol7773 3 жыл бұрын
What did you do to have the type appear when you hover your mouse ? This doesn't happen in my VScode.
@dougmilford7814
@dougmilford7814 3 жыл бұрын
You're probably just missing an extension in VS Code. This video goes over the setup. Maybe it'll highlight what's missing. kzfaq.info/get/bejne/nJyknN2a0KuxhJ8.html
@360nickx
@360nickx 4 жыл бұрын
doug_func FTW!!!
@elwiraarkanow7150
@elwiraarkanow7150 3 жыл бұрын
Could you make a video on trait Sometrait { type Sometype; }
@nasrhussain9061
@nasrhussain9061 4 жыл бұрын
10:50
@_myron
@_myron 4 жыл бұрын
14:37 oh no no no... thats absolutely hideous
Rust Ownership and Borrowing
38:21
Doug Milford
Рет қаралды 66 М.
Rust Lifetimes
26:52
Doug Milford
Рет қаралды 50 М.
100😭🎉 #thankyou
00:28
はじめしゃちょー(hajime)
Рет қаралды 57 МЛН
FOOTBALL WITH PLAY BUTTONS ▶️❤️ #roadto100million
00:20
Celine Dept
Рет қаралды 17 МЛН
When Jax'S Love For Pomni Is Prevented By Pomni'S Door 😂️
00:26
TRY NOT TO LAUGH 😂
00:56
Feinxy
Рет қаралды 10 МЛН
Rust Generics and Traits: Define Common Struct Behaviors 🦀
32:23
Trevor Sullivan
Рет қаралды 3,8 М.
Rust Structs, Traits and Impl
24:53
Doug Milford
Рет қаралды 33 М.
Rust Functions and Procedures
13:31
Doug Milford
Рет қаралды 11 М.
Rust: Generics, Traits, Lifetimes
35:34
The Dev Method
Рет қаралды 44 М.
Rust String vs str slices
14:58
Doug Milford
Рет қаралды 23 М.
ARRAYLIST VS LINKEDLIST
21:20
Core Dumped
Рет қаралды 49 М.
Generic Traits, Impls, and Slices in Rustlang
18:05
chris biscardi
Рет қаралды 10 М.
Rust Primitives (basic data)
14:27
Doug Milford
Рет қаралды 12 М.
Considering Rust
1:03:57
Jon Gjengset
Рет қаралды 189 М.
Rust Conditional Statements
11:38
Doug Milford
Рет қаралды 8 М.
keren sih #iphone #apple
0:16
Muhammad Arsyad
Рет қаралды 1,3 МЛН
Очиститель экрана • 160418185                       Делюсь обзорами в профиле @lykofandrei
0:14
wireless switch without wires part 6
0:49
DailyTech
Рет қаралды 3,2 МЛН
Интереснее чем Apple Store - шоурум BigGeek
0:42