Тёмный
No video :(

Adding Functionality to Data Types - Idiomatic Rust in Simple Steps part 9 

Fio's Quest
Подписаться 659
Просмотров 370
50% 1

Опубликовано:

 

29 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 11   
@LoZander
@LoZander Месяц назад
I really like how you introduce Rust features and patterns in relation to each other instead of in isolation. There's a natural flow to how one leads to the other
@FiosQuest
@FiosQuest Месяц назад
Thank you! This one came together really naturally, but idioms and patterns are something I'm keeping my eye out for :)
@LoZander
@LoZander Месяц назад
very nice introduction to impl, generics and type state pattern (does this fall under that?)! If you always want a cat to be in one of these moods, another approach could be to inverse the model by making the cat type generic with a "mood". Then you can impl sleep only on Cat. This would also make all the general cat behaviour accessible no matter mood. You could then restrict this mood generic to a mood trait which you only implement on the type states :D Ofc. the downside of this approach is that you lose the general state machine and would have to implement the transitions on each animal, if you wanted to use the pattern on multiple animals.
@FiosQuest
@FiosQuest Месяц назад
Shh, you'll spoil the next one 😅 You are absolutely right but you can keep the default behaviour with Traits 😉
@LoZander
@LoZander Месяц назад
@@FiosQuest sorry 😅😂 But im sure you'll put it much more eloquently than I 😊
@LoZander
@LoZander Месяц назад
@@FiosQuest im looking forward to seeing the next one and how you use traits in it 😄
@FiosQuest
@FiosQuest Месяц назад
@@LoZander Haha, nothing to be sorry about, I'm delighted its gelling with you 😅
@misterwoody_
@misterwoody_ 19 дней назад
Is the idiomatic rust name for a "static type" an "associated type"? (e.g. the new function). And also a getter is called a method?
@FiosQuest
@FiosQuest 18 дней назад
Hi there! I'm not sure what a "static type" would be normally. "Static typing" in languages is when a language won't allow you to change the type of a variable. Eg, statically typed languages, which Rust is, don't allow you to do something like: let a = 10; a = "bob"; // this won't work as a is a number There are many statically typed languages that do this including; C, C++, Java, Go, and more! Static values are achievable in Rust as well using the "const" keyword which I haven't gone over yet. There is also the concept of static lifetimes (&'static) in Rust which are given to any value that is guaranteed to always be accessible because it was built in at compile time, eg: let a = "hello"; This technically has a static lifetime as the value "hello" will be part of the compiled binary and therefore always exist while the program is running. Static methods are also something in Rust which are functions that are attached to Types, such as "new" or other constructors which are not part of the instantiated value. Rust has a concept of Associated Types which are a more advanced topic where Traits can specify a type that is actually chosen when the trait is implemented. An example of this is the Iterator trait which has an associated Item type that you must explicitly decide on when implementing Iterator. See: doc.rust-lang.org/std/iter/trait.Iterator.html Getters are a subset of methods. Methods are functions that will work on an instantiated type (a value of a given type) and will allow you to "get" data from inside of the constructed value, usually something that might otherwise be private. This is really helpful to restrict _how_ data can be accessed and manipulated. I appreciate this is a fairly light touch explanation, I hope it helps. LMK if I can clarify anything further.
@misterwoody_
@misterwoody_ 18 дней назад
@@FiosQuest Ah apologies - I meant "Static method" - so the equivalent of what would be called on a class in java or C sharp rather than an instance. That will teach me to comment at midnight :) And the rust term I think is Associated function (which is what I actually meant to write)
@FiosQuest
@FiosQuest 18 дней назад
Ah yes, quite right! I should be careful to use the correct terminology. ☺️
Далее
Enums considered harmful
9:23
Просмотров 203 тыс.
Rust Demystified 🪄 Simplifying The Toughest Parts
14:05
WELCOME TO THE FAMILY, MOE! (Brawl Stars Animation)
00:40
Generics: The most intimidating TypeScript feature
18:19
All Rust string types explained
22:13
Просмотров 166 тыс.
Rust Powered Polymorphism ⚡️ With Traits
9:55
Просмотров 97 тыс.
Memory - Part 2 of Idiomatic Rust in Simple Steps
18:08
Turns out REST APIs weren't the answer (and that's OK!)
10:38
The Most Legendary Programmers Of All Time
11:49
Просмотров 553 тыс.
All Rust features explained
21:30
Просмотров 304 тыс.
Dear Game Developers, Stop Messing This Up!
22:19
Просмотров 707 тыс.
I've been using Redis wrong this whole time...
20:53
Просмотров 355 тыс.
WELCOME TO THE FAMILY, MOE! (Brawl Stars Animation)
00:40