Rust Structs, Traits and Impl

Ғылым және технология

And in-depth discussion about Rust Structs, Traits and Implementations.
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!

Пікірлер: 79

  • @coderoam
    @coderoam3 жыл бұрын

    This person is awesome.

  • @ExpHPKun
    @ExpHPKun4 жыл бұрын

    16:05 A correction: Only the crate that defines a type can add inherent methods to it (it is merely that you are allowed to do it in any *module* of that crate). If you want to add methods to a type in some library you depend on (or to e.g. a primitive type like i32), then you have to put them on a trait and implement it for those types (and then code that wants to use those methods must import the trait). This pattern is known as writing an "extension trait."

  • @nonefvnfvnjnjnjevjenjvonej3384
    @nonefvnfvnjnjnjevjenjvonej338414 күн бұрын

    i have been binging your videos doug and commenting everywhere on your channel.. but seriously thank you so much for these... i wish i could send you a gift or a coffee for all your work... you remind me of two other video teachers I have had in my life: Jeffrey Way and John Lindquist. Some of the best teachers on the planet and noone came close to them so far until now.. You are on the same pedestal for me.

  • @wiktorwektor123
    @wiktorwektor1234 жыл бұрын

    I was learning Rust after knowing C++ and for the first week I hated compiler because it's constant errors reporting and refusing to compile code. It's like grammar teacher but worse. It will fail your test after just one mistake. Now after 1 month I can't imagine life without Rust compiler. It's called Stocholm Syndrome? :D Great tutorial Doug, best I saw on KZread.

  • @dougmilford7814

    @dougmilford7814

    4 жыл бұрын

    Yeah, it's funny... at first you hate it, and then you love it. I think that's often the case when you're learning something very new and you have to break your assumptions. Well worth it, though!

  • @ringoffire0
    @ringoffire0 Жыл бұрын

    9:10 "It's easy to get used to - _the water is warm_ " I might steal this

  • @DennisPing
    @DennisPing2 жыл бұрын

    I like this style of teaching.

  • @debarghyachakraborty
    @debarghyachakraborty3 жыл бұрын

    Learning rust after learning other programming languages absolutely boggles mind 🤯. But in these videos its features have been explained to very basic level, comparing them with other language's features make the videos much easier to learn. Thanks Doug.

  • @annismonadjem6901
    @annismonadjem69014 жыл бұрын

    Thanks Doug for the excellent training on Rust. When will you have your Generics video ready ? Also, I would love to see more of your fantastic video's in Rust and in particular more intermediary and advanced projects and topics in Rust. Doug is the Best of the Best !

  • @avarise5607
    @avarise56073 жыл бұрын

    I am so happy to be able to have such high quality explanation for free. Thank you, from a new CS student from Poland!

  • @TreeLuvBurdpu
    @TreeLuvBurdpu2 жыл бұрын

    You can use alt-up-arrow/alt-down-arrow in VS Code to move lines up or down to make your field-sorting even more efficient.

  • @klimentdukovski

    @klimentdukovski

    Жыл бұрын

    woah, thanks!

  • @teamunicycle
    @teamunicycle Жыл бұрын

    I have just discovered your channel with this video, and found it very useful. The content is excellent, but what struck me are two things about the production: no background music - I'm hearing impaired so clarity is extra important to me; and the pacing is great, particularly because you don't edit out pauses, allowing me to follow along without having to continually pause and step back (as much). I look forward to watching more of your videos.

  • @tobuslieven
    @tobuslieven Жыл бұрын

    I think I've heard the ampersand mentioned in relation to dereferencing, coercion, and borrowing. Looking forward to understanding it better. These videos are fantastic. I really appreciate them.

  • @Mephistel
    @Mephistel4 жыл бұрын

    23:05 You can derive the Default trait like this as well. When you don't care about what values struct members take so long as they are valid, this can be a faster option. It'll work as long as all the member types have a implementation for Default, which is true for all primitive types and a lot of other standard types. Just adding this since I looked up Default trait in the Docs and others might also be curious.

  • @dougmilford7814

    @dougmilford7814

    4 жыл бұрын

    Yeah, good tip! Thanks :)

  • @renetchi
    @renetchi3 жыл бұрын

    This is amazing! I love your way of talking. Fun, concise and simple.

  • @Baron-digit
    @Baron-digit3 жыл бұрын

    Doug, you rock. I think your videos are super helpful! Definitely deserve more subs!

  • @ChumX100
    @ChumX1002 жыл бұрын

    Just a small detail: The definition order of fields in structs is not completely irrelevant. If you derive Ord or PartialOrd, the order of the objects will be based on the order of each field, with the fields defined first taking precedence over the ones defined after.

  • @okarakoo
    @okarakoo4 жыл бұрын

    Impressed with the quality of your tutorial, subscribed and can only hope you can keep making more videos!

  • @dougmilford7814

    @dougmilford7814

    4 жыл бұрын

    Oh, thanks! Yeah, I'm working on a new video as we speak and I have whole a ton of topics I want to get to.

  • @beriu3512
    @beriu35122 жыл бұрын

    Great video, a ton of information perfectly packed without being too overwhelming

  • @chrisjudge705
    @chrisjudge7054 жыл бұрын

    Thank you sooooo much, very good didactics, clear, concise, a warm friendly voice, I love you, as a BRO :-) :-), please more, sugestion if you like, Rust and Vulcan API, 1000 Thanks

  • @dougmilford7814

    @dougmilford7814

    4 жыл бұрын

    I'm glad you like them! I'll take your suggestion into serious consideration. I probably wouldn't be able to get to it for a while because I have a lot of other topics I want to get to first. And, that pesky thing called life keeps getting in the way :) But I'll definitely put it on my list. If more people ask for it, I'll prioritize it.

  • @chrisjudge705

    @chrisjudge705

    4 жыл бұрын

    Thanks, no hurry, oooonly! an idea ;-). The reason was, Vulkan (with Vulkano Wrapper for Rust) is OS agnostic, runs everywhere, Rust runs everywhere, Rust tools Visual Studio Code runs everywhere, so for high performance applications on all plattforms I think this is perhaps a good idea. So this was ooooonly a little small tiny suggestion ;-) Best wishes from Berlin

  • @dougmilford7814

    @dougmilford7814

    4 жыл бұрын

    I agree that it's an important topic. I'm all about cross-platform, hence one of the reasons I love Rust so much. There's a new API standard called WebGPU if you haven't heard of it, and there are some Rust crates actively working on that. I'm super excited! It will be a major leap forward with native/web graphics efficiency, but also cross-platform capabilities. But, it also increases complexities... always a trade-off, right? In any case, I'm salivating for when all platforms can have the same efficient, powerful API implementation.

  • @chrisjudge705

    @chrisjudge705

    4 жыл бұрын

    Thanks for the hint, I have not recognized the difference WebGL and WebGPU

  • @dickheadhex418

    @dickheadhex418

    3 жыл бұрын

    @@chrisjudge705 webgl is the API standard based on opengl ES with some modifications (maybe), implemented by and available in most browsers only. WebGPU is a newer graphics API standard equivalent to opengl or directx and it will be based on vulcan. moreover it wont just be implemented by browsers, but also as SDK extensions for native platforms. So webGPU api will be available as a cross platform vulcan replacemnt(-ish) for native applications also, which you wanted Mr. Milford to cover in his lessons. This is better because the same code will also run in browsers if you switch rust's compile target to wasm

  • @trendingtopicresearch9440
    @trendingtopicresearch9440 Жыл бұрын

    Pure gold for beginners, thank you so much!

  • @wonjunlee5413
    @wonjunlee54132 жыл бұрын

    Best rust tutorial ever

  • @ka1pana
    @ka1pana3 жыл бұрын

    Loving your videos ! Very helpful for absolute beginners with Rust.

  • @AlecHalePletka
    @AlecHalePletka3 жыл бұрын

    Hands-down best Rust series on KZread

  • @Kimdzyytt
    @Kimdzyytt3 жыл бұрын

    4:25 Yeah you are right, "Everything is KEREN..."

  • @puruspace7020
    @puruspace7020 Жыл бұрын

    Thank you Doug, this was very usefull. A friendly, easy to understand tutorial.

  • @kyp0717
    @kyp07172 жыл бұрын

    Thank you! Thank you! Thank you! Your tutorials are excellent!

  • @ManasTunga
    @ManasTunga3 жыл бұрын

    Your tutorials making a tough language easy to learn

  • @ray-lee
    @ray-lee2 жыл бұрын

    best I have seen yet

  • @krtirtho
    @krtirtho3 жыл бұрын

    As a Web-developer the `loosey goosey JavaScript` thing really hurts😂. Well Typescript mitigates many of those pains👍

  • @royendgel
    @royendgel2 жыл бұрын

    The water is warm .. is the 10th time I see this video since 2019

  • @yilmazgunalp
    @yilmazgunalp4 жыл бұрын

    your Rust videos are so good!

  • @timvw01
    @timvw012 жыл бұрын

    Great videos, very helpful

  • @shadorain
    @shadorain3 жыл бұрын

    Totally got a sub from me. This man cracked me up so much! Amazing content too!

  • @greatjobbuddy
    @greatjobbuddy2 жыл бұрын

    Found some great advice in this video managing code.

  • @cool_sarah
    @cool_sarah2 жыл бұрын

    wow thanks for this!

  • @princepandey9453
    @princepandey94533 жыл бұрын

    rust book is quite good but there are some concepts that I am not able to grasp but bow I can cuz of your tutorials ~THANKS!

  • @kartikjavali205
    @kartikjavali2053 жыл бұрын

    This is too fast for a person coming from OOPS world, but I'll keep replaying it! really nice stuff!

  • @atlkurtulmus6993
    @atlkurtulmus69934 жыл бұрын

    Great series! I know it was just to show why consistency matters but i was surprised to see you put a double between a boolean and a int32. Does rust have different allignment rules than c++?

  • @LaurentLaborde
    @LaurentLaborde3 жыл бұрын

    you're a good tutorial person :)

  • @AJ-95
    @AJ-952 жыл бұрын

    I like this guy✌️

  • @HarvardNobody
    @HarvardNobody Жыл бұрын

    Can RUST organize structs internally differently than declared? For example, might it reorganize the above to f64, i32, bool to maximize native alignment? Or does it default to padding out the field bool (followed by three bytes), followed by i32, and f64. For those needing precise positioning of fields I believe the #[repr(C)], #[repr(packed(n))], #[repr(C, align(n))] can be used.

  • @lodoss118
    @lodoss1183 жыл бұрын

    Doug you are awesome

  • @almudza9803
    @almudza98033 жыл бұрын

    enjoy with your teaching style

  • @dougmilford7814

    @dougmilford7814

    3 жыл бұрын

    Thank you! 😃

  • @mattetis
    @mattetis Жыл бұрын

    "Structs traits and impl-mentations" 😅 nice one

  • @ati43888
    @ati43888 Жыл бұрын

    Thanks

  • @preeeby
    @preeeby4 жыл бұрын

    Thanks!

  • @dougmilford7814

    @dougmilford7814

    4 жыл бұрын

    Yep yep :)

  • @jaymartinez311
    @jaymartinez3113 жыл бұрын

    I abstract functions and computed properties in swift for ios just like rust in what is called an extension. Also traits are basically protocols in swift. So learning rust is becoming kinda easy but those damn lifetimes are driving me nuts! I have seen you can declare a lifetime wit a '_ vs lets say 'a.

  • @samuelemmettbray
    @samuelemmettbray2 жыл бұрын

    There will be a DougStruct in all my Rust code; forever.

  • @aqua3418
    @aqua34182 жыл бұрын

    I believe you can also do Default::default()

  • @sc5shout
    @sc5shout2 жыл бұрын

    Referring to alphabetical order of struct vars. Shouldn’t they be declared from the biggest to the smallest to reduce padding/alignment? Or rust’s compiler is smarter than C++’s in this case?

  • @yzzyyzzyyzzy
    @yzzyyzzyyzzy4 жыл бұрын

    good job

  • @dougmilford7814

    @dougmilford7814

    4 жыл бұрын

    Ah, thanks!

  • @MrRushifyIt
    @MrRushifyIt4 жыл бұрын

    ayyyy

  • @akhmad84669
    @akhmad846692 ай бұрын

    4:32 KEREN, hahahahahaha

  • @abdulrachman3313
    @abdulrachman33133 жыл бұрын

    4:23 everything is Keren.

  • @thekiller9710
    @thekiller97102 жыл бұрын

    "Water is warm" 😂😂

  • @JEBailey
    @JEBailey4 жыл бұрын

    The waters warm?

  • @dougmilford7814

    @dougmilford7814

    4 жыл бұрын

    Ha, ha, ha... didn't like that one, huh? Eh, they all can't be winners.

  • @jairwen82
    @jairwen822 жыл бұрын

    😂,angry sound is funny

  • @Lord2225
    @Lord22253 жыл бұрын

    This is like C but save.

  • @reheyesd8666
    @reheyesd86663 жыл бұрын

    Maybe i will just stick to Python, this is difficult

  • @scottb4029
    @scottb4029 Жыл бұрын

    The waters warm........... Who pee-ed?

  • @-taz-
    @-taz-4 жыл бұрын

    IMO, "#[allow(unused_variables)] //This is so I don't get warnings throughout the demo" is slightly more intrusive than yellow squiggles. :)

  • @dougmilford7814

    @dougmilford7814

    4 жыл бұрын

    Fair enough :)

  • @danvilela

    @danvilela

    3 жыл бұрын

    I like it.. i hate those warnings

  • @krellin
    @krellin3 жыл бұрын

    composition is great, but it is bad to enforce it and give no other choice... smart programmers know when to use what it would be weird to define a Duck as something that has Animal )

  • @arturczajkowski4255
    @arturczajkowski42554 жыл бұрын

    16:05, this will lead to a complete mess in large projects...