26
11
submitted 2 years ago* (last edited 2 years ago) by Jayjader@jlai.lu to c/learningrustandlemmy@lemmy.ml

What?

I will be holding the tenth 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 covered defining and instantiating structs with section 1 of chapter 5, "Using Structs to Structure Related Data". We'll be continuing with section 2, where we'll be writing some code!

Previous session details and recording can be found in the following lemmy post: https://jlai.lu/post/6703544

Why?

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)

When ?

Currently, I intend to start at 18:00 UTC+2 (aka 6pm Central European Time) on Monday (2023-05-20). If you were present for a previous session, then basically the same time-of-day and day-of-week as that one was.

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.

How ?

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

EDIT: here's the recording https://youtu.be/s0U7KBXxL8g

I will have on-screen:

  • the BU online version of The Book
  • a terminal session with the necessary tooling installed (notably rustup and through it cargo & "friends")
  • some form of visual aid (currently a digital whiteboard using www.excalidraw.com)
  • the live stream's chat

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.

Who ?

You! (if you're interested). And, of course, me.

27
5
28
15
submitted 2 years ago* (last edited 2 years ago) by maegul@lemmy.ml to c/learningrustandlemmy@lemmy.ml

We've got two parallel streams going here. One is up to chapter 10 on Traits and the other on chapter 5 on Structs & Enums.

  • How are we feeling about Rust the language?
  • Any persistent confusions or difficulties?
  • Favourite features or success stories?
  • How are we finding "The Book" in general?
    • Personally, I think it's good but not great and am definitely reaching out for other learning experiences or materials, lately finding myself going through the Std Lib Docs a bit
    • Andy Balaam's Rust Tutorial Series over on peertube are also good and I recently remembered to watch them as I go

Otherwise ... any thoughts or requests on what else can happen here for those going through "The Book"?

  • I'm thinking of having posts on sets of chapters once the two twitch streams have gotten up to them.
  • So right now, both have gotten through the borrow checker chapter (ch 4).
  • The idea would be to have a reading club happen here too ... to allow written discussion/questions here for those not able to make the streams (or who like/prefer written discussion), but also to provide a retrospective for those who've gone through the streams.
  • Personally, in these discussions I'd post my understanding of the topic, look back on the quizzes to see what tripped me up, or any other practical issues I ran into, and post anything else I may have found that helped me on the topic. Basically to see what I actually learned from that chapter.
  • Thoughts??
  • Another thing I can think of is challenges and exercises. I tried one a while back, but I think it was too much/long, so smaller exercises would probably work better for getting us thinking/coding in rust. AoC has come up and there are plenty of others. Would regular posts from such a thing be welcome or helpful??
29
14
submitted 2 years ago* (last edited 2 years ago) by Jayjader@jlai.lu to c/learningrustandlemmy@lemmy.ml

Ownership is finally over! Ok, I know we're going to be seeing more of it throughout the rest of the book, but at least it should always be in the context of "doing" something else/useful. For example, grouping bits of related data into structs.

What?

I will be holding the ninth 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).

This week we begin chapter 5 "Using Structs to Structure Related Data"!

Previous session details and recording can be found in the following lemmy post: https://jlai.lu/post/6557213

Why?

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)

When ?

Currently, I intend to start at 18:00 UTC+2 (aka 6pm Central European Time) on Monday (2023-05-13). If you were present for a previous session, then basically the same time-of-day and day-of-week as that one was.

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.

How ?

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

Edit: here's the link to the recording https://youtu.be/h4l5Ksd5w7E

I will have on-screen:

  • the BU online version of The Book
  • a terminal session with the necessary tooling installed (notably rustup and through it cargo & "friends")
  • some form of visual aid (currently a digital whiteboard using www.excalidraw.com)
  • the live stream's chat

I will steadily progress through the chapter, both reading aloud the literal chapter 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.

Who ?

You! (if you're interested). And, of course, me.

30
10
submitted 2 years ago* (last edited 2 years ago) by Jayjader@jlai.lu to c/learningrustandlemmy@lemmy.ml

What?

I will be holding the eighth 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).

This week we finish chapter 4: "Understanding Ownership" by reading through the "Ownership Recap (4.5).

Previous session details and recording can be found in the following lemmy post: https://jlai.lu/post/6353244

Why?

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)

When ?

Currently, I intend to start at 18:00 UTC+2 (aka 6pm Central European Time) on Monday (2023-05-06). That's around 4 hours after this post is created. If you were present for a previous session, then basically the same time-of-day and day-of-week as that one was.

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.

How ?

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

EDIT: here's the recording: https://youtu.be/3w7m5GM7eV8

I will have on-screen:

  • the BU online version of The Book
  • a terminal session with the necessary tooling installed (notably rustup and through it cargo & "friends")
  • some form of visual aid (currently a digital whiteboard using www.excalidraw.com)
  • the live stream's chat

I will steadily progress through the chapter, both reading aloud the literal chapter 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.

Who ?

You! (if you're interested). And, of course, me.

31
23

This might be a more interesting dive into Rust for those with a fair amount of existing c and/or c++.

I tried it out myself a few years ago. I had fun reliving the nightmare of implementing doubly-linked lists in C back in school! I never made it to the end of the book, though; it got wayyyy more complex around halfway than I could process at the time.

32
12
submitted 2 years ago* (last edited 2 years ago) by Jayjader@jlai.lu to c/learningrustandlemmy@lemmy.ml

Hi all! So much happening in my personal life these past 2 weeks that I couldn't put aside the time or energy to host these sessions. Things are calming down a bit (plus I've missed doing the sessions), and so I'm happy to announce the date for the next session.

What?

I will be holding the seventh 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).

This week we will be continuing chapter 4: "Understanding Ownership". Last session we finished "Fixing Ownership Errors" (4.3). We will thus start from the beginning of "The Slice Type" (4.4).

Previous session details and recording can be found in the following lemmy post: https://jlai.lu/post/5991675

Why?

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)

When ?

Currently, I intend to start at 18:00 UTC+2 (aka 6pm Central European Time) on Monday (2023-04-29). If you were present for a previous session, then basically the same time-of-day and day-of-week as that one was.

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.

How ?

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). Edit: here's the recording: https://youtu.be/OeyWDSJ-Y5E

I will have on-screen:

  • the BU online version of The Book
  • a terminal session with the necessary tooling installed (notably rustup and through it cargo & "friends")
  • some form of visual aid (currently a digital whiteboard using www.excalidraw.com)
  • the live stream's chat

I will steadily progress through the chapter, both reading aloud the literal chapter 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.

Who ?

You! (if you're interested). And, of course, me.

33
14

Just place to keep links to comments from this community that go "above and beyond" in helping someone out and really explaining or teaching.

There'll be a link in the side bar.

Feel free to add any links you like with a comment

34
24

A minor but interesting and illuminating point came up in a conversation that I thought was worth sharing, for those learning rust, in a separate post. I'm mostly just copy-and-pasting here.


TL;DR: The patterns you use in match statements and related syntax are (basically) available to you in let statements. This is how destructuring works!! And what they're for with let. But the patterns have to be "irrefutable"


IE, they have to always be able to match the expression/value.


For those who aren't aware, here's the first section in The Book on patterns in let statements.

I think, if this is confusing, there are two points of clarification:

  1. All let statements involve patterns (as Ephera states). They're all let PATTERN = EXPRESSION.
    • For ordinary variable binding, we're just providing a basic pattern that is essentially like a wildcard in that it will match the totality of any expression and so be bound to the full/final value of that expression.
    • It's only when the pattern becomes more complex that the pattern matching part becomes evident, as elements of the value/expression are destructured into those of the pattern.
    • EG, let (x, y, _) = (1, 2, 3); or Ephera's example below let Something(different_thing) = something; which extracts the single field of the struct something into the variable different_thing (handy!).
  2. let statements must use irrefutable patterns. That is, patterns that cannot fail to match the expression.
    • For example, against a tuple, (x, y, _) will always match. Another way of putting it: irrefutable patterns are about destructuring not testing or conditional logic.
    • if let statements on the other hand can take both irrefutable patterns and refutable, but are really intended to be used with refutable patterns as they're intended for conditional logic where the pattern must be able to fail to match the expression/value.
    • See The Book chapter on refutability

The nice and useful example provided by @Ephera@lemmy.ml (in the original comment):

struct Something(DifferentThing);

let something = Something(DifferentThing::new());

let Something(different_thing) = something;
  • Here, the variable something is a struct of type Something which contains one field of type DifferentThing.
  • In the final line, we're extracting that DifferentThing field with a pattern in a let statement.
  • IE, Something(different_thing) is the pattern. And it is irrefutable against all variables of type Something, as they have only one field.
35
9

I can't help but suspect it doesn't offer much and you may as well just use match statements for whenever you want pattern matching, however many times it might be slightly more verbose than what you could do with if let.

I feel like I'd easily miss that pattern matching was happening with if let but will always know with match what's happening and have an impression of what's happening just from the structure of the code.

36
8
37
7
submitted 2 years ago* (last edited 2 years ago) by Jayjader@jlai.lu to c/learningrustandlemmy@lemmy.ml

Hi all!

What?

I will be holding the sixth 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).

This week, we will be continuing chapter 4: "Understanding Ownership". Last week we finished "References and Borrowing" (4.2). We will thus start from the beginning of "Fixing Ownership Errors" (4.3).

Previous session details and recording can be found in the following lemmy post: https://jlai.lu/post/5871866

Why?

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)

When ?

Currently, I intend to start at 18:00 UTC+1 (aka 6pm Central European Time) on Monday (2023-04-15). If you were present for a previous session, then basically the same time as that one was.

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.

How ?

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). Edit: here's the recording: https://youtu.be/7XcluwdxBHQ

I will have on-screen:

  • the BU online version of The Book
  • a terminal session with the necessary tooling installed (notably rustup and through it cargo & "friends")
  • some form of visual aid (currently a digital whiteboard using www.excalidraw.com)
  • the live stream's chat

I will steadily progress through the chapter, both reading aloud the literal chapter 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.

Who ?

You! (if you're interested). And, of course, me.

38
18
submitted 2 years ago* (last edited 2 years ago) by Jayjader@jlai.lu to c/learningrustandlemmy@lemmy.ml

Hi all! I had to cancel last week's session at the last minute, so this week we'll just be covering what we would have covered, then.

(recap of the session info for completeness' sake:)

What?

I will be holding the fifth 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). This week, we will be continuing chapter 4: "Understanding Ownership".

Previous session details and recording can be found in the following lemmy post: https://jlai.lu/post/5452538

Why?

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)

When ?

Currently, I intend to start at 18:00 UTC+1 (aka 6pm Central European Time) on Monday (2023-04-08). If you were present for a previous session, then basically the same time as that one was.

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.

How ?

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). Edit: the recording is now uploaded on youtube: https://youtu.be/zueZGhlkiyE

I will have on-screen:

  • the BU online version of The Book
  • a terminal session with the necessary tooling installed (notably rustup and through it cargo & "friends")
  • some form of visual aid (currently a digital whiteboard using www.excalidraw.com)
  • the live stream's chat

I will steadily progress through the chapter, both reading aloud the literal chapter 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.

Who ?

You! (if you're interested). And, of course, me.

39
43

Hey!

I'm a professional software engineer with several years of experience using Rust. Unfortunately I don't really have the time to contribute to Lemmy directly myself, but I love teaching other people Rust so if:

  • You are curious about Rust and why you should even learn it
  • You are trying to learn Rust but maybe having a hard time
  • You are wondering where to start
  • You ran into some specific issue

... or anything to do with Rust really, then feel free to ask in the comments or shoot me a PM 🙂

40
8
submitted 2 years ago* (last edited 2 years ago) by Jayjader@jlai.lu to c/learningrustandlemmy@lemmy.ml

Edit: I'm currently feeling too unwell to host the reading club this evening.

Hi all!

What?

I will be holding the fifth 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). This week, we will be continuing chapter 4: "Understanding Ownership".

Previous session details and recording can be found in the following lemmy post: https://jlai.lu/post/5452538

Why?

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)

When ?

Currently, I intend to start at 18:00 UTC+1 (aka 6pm Central European Time) on Monday (2023-04-01). If you were present for a previous session, then basically the same time as that one was.

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.

How ?

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:

  • the BU online version of The Book
  • a terminal session with the necessary tooling installed (notably rustup and through it cargo & "friends")
  • some form of visual aid (currently a digital whiteboard using www.excalidraw.com)
  • the live stream's chat

I will steadily progress through the chapter, both reading aloud the literal chapter 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.

Who ?

You! (if you're interested). And, of course, me.

41
11

cross-posted from: https://lemmy.world/post/13508677

Hello All:

I am working on rust problems here. In the second question I solved it by simply adding the return statement for the function to modify. I am not sure what the lesson in ownership to walk away with in this problem. Any guidance?

42
9
submitted 2 years ago* (last edited 2 years ago) by Jayjader@jlai.lu to c/learningrustandlemmy@lemmy.ml

Hi all!

What?

I will be holding the fourth 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). This week, we will be starting chapter 4: "Understanding Ownership".

Previous session details and recording can be found in the following lemmy post: https://jlai.lu/post/5278834

Why?

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)

When ?

Currently, I intend to start at 18:00 UTC+1 (aka 6pm Central European Time) on Monday (2023-03-25). If you were present for a previous session, then basically the same time as that one was.

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.

How ?

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). Edit: the recording can be found at the following link: https://youtu.be/YmMreNK3fcw.

I will have on-screen:

  • the BU online version of The Book
  • a terminal session with the necessary tooling installed (notably rustup and through it cargo & "friends")
  • some form of visual aid (currently a digital whiteboard using www.excalidraw.com)
  • the live stream's chat

I will steadily progress through the chapter, both reading aloud the literal chapter 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.

The interactive quizzes have started getting more interesting! Unfortunately, we're still on a decent delay from when I'm speaking to when I see people's comments appear in chat, so we will most likely continue to work through them in a more disjointed manner than the rest of the material.

Who ?

You! (if you're interested). And, of course, me.

43
7

General page for challenges for learning rust

Writing a Diff

  • First posed here
  • Check in for solutions/statuses here
44
17

Intro

Not long ago I posed a challenge for those of us learning rust: https://lemmy.ml/post/12478167.

Basically write an equivalent of git diff --no-index A B ... a file differ.

While it's never too late to attempt it, I figured it'd be a good time to check in to see what anyone thought of it, in part because some people may have forgotten about it and would still like to have a shot, and also because I had a shot and am happy with what I wrote.

Check In

I'll post where I got up to below (probably as a comment), but before that, does anyone have anything to share on where they got up to ... any general thoughts on the challenge and the general idea of these?

My experience

My personal experience was that I'd not kept up with my rust "studies" for a bit and used this as a good "warm up" or "restart" exercise and it worked really well. Obviously learning through doing is a good idea, and the Rust Book is a bit too light, IMO, on good exercises or similar activities. But I found this challenge just difficult enough to make me feel more comfortable with the language.

Future Challenges

Any ideas for future challenges??

My quick thoughts

  • A simple web app like a todo app using axtix_web and diesel and some templating crate.
  • Extend my diffing program to output JSON/HTML and then to diff by characters in a string
  • A markdown parser??
45
9

Quick little confusion or even foot-gun I ran into (while working on the challenge I posed earlier).

TLDR

My understanding of what I ran into here:

  • Matching on multiple variables simultaneously requires assigning them to a tuple (?),
  • which happens more or less implicitly (?),
  • and which takes ownership of said variables.
  • This ownership doesn't occur when matching against a single variable (?)
  • Depending on the variables and what's happening in the match arms this difference can be the difference between compiling and not.

Anyone got insights they're willing to share??

Intro

I had some logic that entailed matching on two variables. Instead of having two match statements, one nested in the other, I figured it'd be more elegant to match on both simultaneously.

An inline tuple seemed the obvious way to do so and it works, but it seems that the tuple creates some ownership problems I didn't anticipate, mostly because I was thinking of it as essentially syntax and not an actual tuple variable.

As you'll see below, the same logic with nested match statements each on a single variable doesn't suffer from the same issues.

Demo Code

fn main() {

    // # Data structures
    enum Kind {
        A,
        B
    }
    struct Data {
        kind: Kind
    }

    // # Implementation
    let data = vec![Data{kind: Kind::A}];

    // ## Basic idea: process two adjacent data points
    let prev_data = data.last().unwrap();
    let new_data = Data{kind: Kind::B};

    //
***
MATCH STATEMENTS
***

    // ## This works: match on one then the other
    let next_data = match prev_data.kind {
        Kind::A => match new_data.kind {
            Kind::A => 1,
            Kind::B => 2,
        },
        Kind::B => match new_data.kind {
            Kind::A => 3,
            Kind::B => 4,
        },
    };

    // ## This does NOT work: match on both
    let next_data2 = match (prev_data.kind, new_data.kind) {
        (Kind::A, Kind::A) => 1,
        (Kind::A, Kind::B) => 2,
        (Kind::B, Kind::A) => 3,
        (Kind::B, Kind::B) => 4,
    };
}

The Error

The error is on the line let next_data = match (prev_data.kind, new_data.kind), specifically the tuple and its first element prev_data.kind, with the error:

error[E0507]: cannot move out of `prev_data.kind` which is behind a shared reference

move occurs because `prev_data.kind` has type `Kind`, which does not implement the `Copy` trait

The Confusion

So prev_data.kind needs to be moved. That's ok. Borrowing it with (&prev_data.kind, ...) fixes the problem just fine, though that can cause issues if I then want to move the variable within the match statement, which was generally the idea of the logic I was trying to write.

What got me was that the same logic but with nested match statements works just fine.

I'm still not clear on this, but it seems that the inline tuple in the second tuple-based approach is a variable that takes ownership of the variables assigned to it. Which makes perfect sense ... my simple mind just thought of it as syntax for interleaving multiple match statements I suppose. In the case of nested match statements however, I'm guessing that each match statement is its own scope.

The main thing I haven't been able to clarify is what are the ownership dynamics/behaviours of match statements?? It seems that there's maybe a bit happening implicitly here?? I haven't looked super hard but it does seem like something that's readily glossed over in the materials I've seen thus far??

General Implications

AFAICT:

  • if you want to match on two or more variables simultaneously, you'll probably need borrow them in the match statement if they're anything but directly owned variables.
  • If you want to then use or move them in the match arms you may have to wrangle with ownership or just use nested match statements instead (or refactor your logic/implementation).
  • So probably don't do multi-variable matching unless the tuple of variables is a variable native to the logic?
46
8
submitted 2 years ago* (last edited 2 years ago) by Jayjader@jlai.lu to c/learningrustandlemmy@lemmy.ml

Hi all!

What?

I will be holding the third 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). This week, we will be continuing (and hopefully concluding) chapter 3: "Common Programming Concepts". Last session covered sections 3.1 and 3.2; this session will start at section 3.3 (Functions).

Previous session details and recording can be found in the following lemmy post: https://jlai.lu/post/5036425

Why?

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)

When ?

Currently, I intend to start at 18:00 UTC+1 (aka 6pm Central European Time) on Monday (2023-03-18). If you were present for a previous session, then basically the same time as that one was.

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.

How ?

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

Edit: the session recording is available at the following link: https://youtu.be/v5b6UIDZQ5A

I will have on-screen:

  • the BU online version of The Book
  • a terminal session with the necessary tooling installed (notably rustup and through it cargo & "friends")
  • some form of visual aid (currently a digital whiteboard using www.excalidraw.com)
  • the live stream's chat

I will steadily progress through the chapter, both reading aloud the literal chapter 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.

The interactive quizzes have started getting more interesting! Unfortunately, we're still on a decent delay from when I'm speaking to when I see people's comments appear in chat, so we will most likely continue to work through them in a more disjointed manner than the rest of the material.

Who ?

You! (if you're interested). And, of course, me.

47
16
submitted 2 years ago* (last edited 2 years ago) by Jayjader@jlai.lu to c/learningrustandlemmy@lemmy.ml

Hi all!

What?

I will be holding the second 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). This week, we will be starting chapter 3: "Common Programming Concepts".

Previous session details and recording can be found in the following lemmy post: https://jlai.lu/post/4802347

Why?

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 first/previous session)

When ?

Currently, I intend to start at 18:00 UTC+1 (aka 6pm Central European Time) on Monday (2023-03-11). If you were present for the first session, then basically the same time as that one was.

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.

How ?

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). EDIT: link to recording: https://youtu.be/TnGMnlsT23o

I will have on-screen:

  • the BU online version of The Book
  • a terminal session with the necessary tooling installed (notably rustup and through it cargo & "friends")
  • some form of visual aid (currently a digital whiteboard using www.excalidraw.com)
  • the live stream's chat (probably)

I will steadily progress through the chapter, both reading aloud the literal chapter 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.

The interactive quizzes have so far been too trivial to warrant working on the answers collectively. This week might prove different; we can see how we prefer to work through them as we encounter them.

Who ?

You! (if you're interested). And, of course, me.

48
37

It seems they’re not far from finishing and have the first few chapters up for early access and feedback. It could be the go to text for learning the protocol.

49
9

cross-posted from: https://discuss.online/post/5803977

About this Book

The Rust programming language is extremely well suited for concurrency, and its ecosystem has many libraries that include lots of concurrent data structures, locks, and more. But implementing those structures correctly can be difficult. Even in the most well-used libraries, memory ordering bugs are not uncommon.

In this practical book, Mara Bos, team lead of the Rust library team, helps Rust programmers of all levels gain a clear understanding of low-level concurrency. You’ll learn everything about atomics and memory ordering and how they're combined with basic operating system APIs to build common primitives like mutexes and condition variables. Once you’re done, you’ll have a firm grasp of how Rust’s memory model, the processor, and the role of the operating system all fit together.

With this guide, you’ll learn:

  • How Rust's type system works exceptionally well for programming concurrency correctly
  • All about mutexes, condition variables, atomics, and memory ordering
  • What happens in practice with atomic operations on Intel and ARM processors
  • How locks are implemented with support from the operating system
  • How to write correct code that includes concurrency, atomics, and locks
  • How to build your own locking and synchronization primitives correctly

Available free of charge. But I doubt I'll ever read it. Never enough time and energy for everything.

50
18
submitted 2 years ago* (last edited 2 years ago) by Jayjader@jlai.lu to c/learningrustandlemmy@lemmy.ml

Hi all!

What?

I will be starting a secondary slot/sessions for the Reading Club, also on "The Book" ("The Rust Programming Language"). We will, also, very likely use the Brown University online edition (that has some added quizzes & interactive elements).

Why?

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.

When ?

Currently, I intend to start at 18:00 UTC+1 (aka 6pm Central European Time). Effectively, this is 6 hours "earlier in the day" than when the main sessions start, as of writing this post.

The first stream will happen on the coming Monday (2023-03-04).

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.

How ?

We will start from the beginning of "The Book".

There are 2 options:

  1. mirror the main sessions' pace (once every week), remaining ~4 sessions "behind" them in terms of progression through "The Book"
  2. attempt to catch up to the main sessions' progression

I am personally interested in trying out 2 sessions each week, until we are caught up. This should effectively result in 2-3 weeks of biweekly sessions before we slow back down. I'm not doing this just for me, however, so if most people joining these sessions prefer the first option I'm happy to oblige.

I will be hosting the session from my own twitch channel, https://www.twitch.tv/jayjader . I'll be recording the session as well;~~this post should be edited to contain the url for the recording, once I have uploaded it~~ here's a youtube link to the recording of the session: https://youtu.be/gQDO_UtXKBg

Who ?

You! (if you're interested). And, of course, me.

view more: ‹ prev next ›

Learning Rust and Lemmy

460 readers
7 users here now

Welcome

A collaborative space for people to work together on learning Rust, learning about the Lemmy code base, discussing whatever confusions or difficulties we're having in these endeavours, and solving problems, including, hopefully, some contributions back to the Lemmy code base.

Rules TL;DR: Be nice, constructive, and focus on learning and working together on understanding Rust and Lemmy.


Running Projects


Policies and Purposes

  1. This is a place to learn and work together.
  2. Questions and curiosity is welcome and encouraged.
  3. This isn't a technical support community. Those with technical knowledge and experienced aren't obliged to help, though such is very welcome. This is closer to a library of study groups than stackoverflow. Though, forming a repository of useful information would be a good side effect.
  4. This isn't an issue tracker for Lemmy (or Rust) or a place for suggestions. Instead, it's where the nature of an issue, what possible solutions might exist and how they could be or were implemented can be discussed, or, where the means by which a particular suggestion could be implemented is discussed.

See also:

Rules

  1. Lemmy.ml rule 2 applies strongly: "Be respectful, even when disagreeing. Everyone should feel welcome" (see Dessalines's post). This is a constructive space.
  2. Don't demean, intimidate or do anything that isn't constructive and encouraging to anyone trying to learn or understand. People should feel free to ask questions, be curious, and fill their gaps knowledge and understanding.
  3. Posts and comments should be (more or less) within scope (on which see Policies and Purposes above).
  4. See the Lemmy Code of Conduct
  5. Where applicable, rules should be interpreted in light of the Policies and Purposes.

Relevant links and Related Communities


Thumbnail and banner generated by ChatGPT.

founded 2 years ago
MODERATORS