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
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.
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.
@@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)