!learningrustandlemmy
@lemmy.mlhttps://github.com/pretzelhammer/rust-blog/blob/master/posts/tour-of-rusts-standard-library-traits.md
Educational blog posts for Rust beginners. Contribute to pretzelhammer/rust-blog development by creating an account on GitHub.
You've gotta be familiar with Traits
to try to work this out.
::: spoiler Just in case you want to try to work it out your self first
Gotta say, after hearing that rust is not an OOP/Class-inheritance language, and is strongly and explicitly typed, the Deref
trait feels like a helluva drug!
Obviously it's not the same thing, but working this out definitely had me making a couple of double takes.
Somewhat awkwardly, I worked it out through the standard lib docs before reading ch 15 of the book (it's more fun this way!).
And for those who want a quick answer:
Deref
docs, especially the deref coercion
partself
in method calls.
Deref
be implemented.sort()
isn't implemented on Vec
, it's implemented on the slice
type ([T]
).Vec
implements Deref
, substituting [T]
for Vec<T>
in all function/method calls.Vec
gets all of the methods implemented on [T]
... almost like Vec
is a subclass of [T]
!I will be holding the fifteenth of the secondary slot/sessions for the Reading Club, also on "The Book" ("The Rust Programming Language"). We are using the Brown University online edition (that has some added quizzes & interactive elements).
Last time we began chapter 7 (Managing Growing Projects with Packages, Crates, and Modules), and read up through section 7.3 (Paths for Referring to an item in the Module Tree). This time we will start at section 7.4 (Bringing Paths Into Scope with the use Keyword).
Previous session details and recording can be found in the following lemmy post: https://jlai.lu/post/8006138
This slot is primarily to offer an alternative to the main reading club's streams that caters to a different set of time zone preferences and/or availability.
(also, obviously, to follow up on the previous session)
Currently, I intend to start at 18:00 UTC+2 (aka 6pm Central European Time) on Monday (2023-07-01). If you were present for a previous session, then basically the same time-of-day and day-of-week as that one was.
EDIT: here's the recording: https://youtu.be/RI4D62MVvCA
Please comment if you are interested in joining because you can't make the main sessions but would prefer a different start time (and include a time that works best for you in your comment!). Caveat: I live in central/western Europe; I can't myself cater to absolutely any preference.
The basic format is: I will be sharing my computer screen and voice through an internet live stream (hosted at https://www.twitch.tv/jayjader for now). The stream will be locally recorded, and uploaded afterwards to youtube (for now as well).
I will have on-screen:
rustup
, cargo
, and clippy
)I will steadily progress through the book, both reading aloud the literal text and commenting occasionally on it. I will also perform any code writing and/or terminal commands as the text instructs us to.
People who either tune in to the live stream or watch/listen to the recording are encouraged to follow along with their own copy of the book.
I try to address any comments from live viewers in the twitch chat as soon as I am aware of them. If someone is having trouble understanding something, I will stop and try to help them get past it.
You! (if you're interested). And, of course, me.
https://doc.rust-lang.org/std/marker/trait.Copy.html
Types whose values can be duplicated simply by copying bits.
I will be holding the fourteenth of the secondary slot/sessions for the Reading Club, also on "The Book" ("The Rust Programming Language"). We are using the Brown University online edition (that has some added quizzes & interactive elements).
Last time we completed chapter 6 (enums & pattern matching). This time we will begin chapter 7 (Managing Growing Projects with Packages, Crates, and Modules).
Previous session details and recording can be found in the following lemmy post: https://jlai.lu/post/7773753
This slot is primarily to offer an alternative to the main reading club's streams that caters to a different set of time zone preferences and/or availability.
(also, obviously, to follow up on the previous session)
Currently, I intend to start at 18:00 UTC+2 (aka 6pm Central European Time) on this day (2023-06-24). If you were present for a previous session, then basically the same time-of-day and day-of-week as that one was.
Here's the recording: https://youtu.be/pUqVmPRLhNE
Please comment if you are interested in joining because you can't make the main sessions but would prefer a different start time (and include a time that works best for you in your comment!). Caveat: I live in central/western Europe; I can't myself cater to absolutely any preference.
The basic format is: I will be sharing my computer screen and voice through an internet live stream (hosted at https://www.twitch.tv/jayjader for now). The stream will simultaneously be recorded locally and uploaded afterwards to youtube (also, for now).
I will have on-screen:
rustup
and through it cargo
& "friends")I will steadily progress through the book, both reading aloud the literal text and commenting occasionally on it. I will also perform any code writing and/or terminal commands as the text instructs us to.
People who either tune in to the live stream or watch/listen to the recording are encouraged to follow along with their own copy of the book.
I try to address any comments from live viewers in the twitch chat as soon as I am aware of them. If someone is having trouble understanding something, I will stop and try to help them get past it.
You! (if you're interested). And, of course, me.
https://rust-book.cs.brown.edu/ch06-04-inventory.html
https://rust-book.cs.brown.edu/ch05-00-structs.html
https://github.com/mawkler/rust-book-to-epub
Rust Book to EPUB converter. Contribute to mawkler/rust-book-to-epub development by creating an account on GitHub.
I will be holding the thirteenth of the secondary slot/sessions for the Reading Club, also on "The Book" ("The Rust Programming Language"). We are using the Brown University online edition (that has some added quizzes & interactive elements).
Last time we started chapter 6 (enums & pattern matching). We read through 6.1 and learned how to define enum
variants in tuple or struct form. We also learned about the Option<T>
enum that Rust provides us with. This time we'll begin section 6.2 and learn about the match
control flow construct.
Previous session details and recording can be found in the following lemmy post: https://jlai.lu/post/7532130
This slot is primarily to offer an alternative to the main reading club's streams that caters to a different set of time zone preferences and/or availability.
(also, obviously, to follow up on the previous session)
Currently, I intend to start at 18:00 UTC+2 (aka 6pm Central European Time) on Monday (2023-06-17). If you were present for a previous session, then basically the same time-of-day and day-of-week as that one was.
EDIT: here's the recording https://youtu.be/W1fjxCwtwfM
Please comment if you are interested in joining because you can't make the main sessions but would prefer a different start time (and include a time that works best for you in your comment!). Caveat: I live in central/western Europe; I can't myself cater to absolutely any preference.
The basic format is: I will be sharing my computer screen and voice through an internet live stream (hosted at https://www.twitch.tv/jayjader for now). The stream will simultaneously be recorded locally and uploaded afterwards to youtube (also, for now).
I will have on-screen:
rustup
and through it cargo
& "friends")I will steadily progress through the book, both reading aloud the literal text and commenting occasionally on it. I will also perform any code writing and/or terminal commands as the text instructs us to.
People who either tune in to the live stream or watch/listen to the recording are encouraged to follow along with their own copy of the book.
I try to address any comments from live viewers in the twitch chat as soon as I am aware of them. If someone is having trouble understanding something, I will stop and try to help them get past it.
You! (if you're interested). And, of course, me.