Learning Rust and Lemmy

226 readers
1 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 1 year ago
MODERATORS
1
 
 

We are officially finished with The Book. Now onto something that matters.

Today is an exploratory session to explore the lemmy codebase, see how well it's documented for contribution, and make a targets for contribution.

If anyones following along this week is dedicated to familiarizing ourselves with the codebase. Pull it down, set up our dev environment, run the code. After that pick a directory and attempt to explain a few functions to a duck. If a duck is not present find a google search result for the term "duck" will suffice.

As always, a stream will be available at the following link of myself doing this for around 2 hours starting one hour after this post is made. https://www.twitch.tv/deerfromsmoke

2
 
 

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?
3
 
 

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.

Who ?

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

4
 
 

For those who don't know, rust-analyzer is the main rust LSP (Language Server Protocol). So super handy! Here's their homepage: https://rust-analyzer.github.io/

I wanted to have it running for little all the programs and tests I'd write and run while going through "The Book" and have settled on a setup I thought I'd share.

The main problem I encountered is that having R-A run on a single file isn't really a thing. It seems it kinda is but I couldn't get it working and it seemed to be a pain anyway. Plus I wanted to be able to use both cargo projects/crates and little test programs/functions simultaneously from a single workspace in my text editor dedicated to working through The Book.

My solution

at the moment

What I settled on was:

  • Running multiple cargo projects under a single instance of rust-analyzer running in a single workspace in my editor
  • Organising simple test programs as specific functions in a single cargo project.
    • So far, I'm thinking of organising these thematically specifical cargo projects. So I've got one called "borrow_checker" for all borrow checker and ownership toy examples.
    • These specific functions can get called from a single main() if helpful/necessary.

EG directory structure:

the_book/
 ├──  Cargo.lock
 ├──  Cargo.toml
 ├──  guessing_game/
 │  ├──  .gitignore
 │  ├──  Cargo.lock
 │  ├──  Cargo.toml
 │  ├──  src/
 │  └──  target/
 ├──  hello_cargo/
 │  ├──  .gitignore
 │  ├──  Cargo.lock
 │  ├──  Cargo.toml
 │  ├──  src/
 │  └──  target/
 ├──  misc_play/
 │  └──  borrow_checker/
 │     ├──  .gitignore
 │     ├──  Cargo.lock
 │     ├──  Cargo.toml
 │     ├──  src/
 │     └──  target/
 └──  target/
    ├──  .rustc_info.json
    ├──  CACHEDIR.TAG
    └──  debug/

Basically everything inside the_book/ is its own cargo project.

And inside misc_play/borrow_checker/src/ is a typical main.rs with multiple functions testing or toying with something I was trying to understand ... and hopefully use the LSP to help me with.

Getting this to work

So that's the structure. But getting it to work requires a little trick. It requires using a Cargo Workspace.

In this case, it's a matter of adding a Cargo.toml file at the top level (ie, the_book/Cargo.toml) with the following:

[workspace]

resolver = "2"
edition = "2021"

members = [
	"guessing_game",
	"hello_cargo",
	"misc_play/borrow_checker"
]

Here, members is clearly listing each of the projects or libraries. And I added the resolver and edition keys to silence a cargo warning about incompatible resolvers (which I don't know anything about).

With this file, when at the top level, one can run cargo build to build all of the projects/packages. Or, cargo build -p SPECIFIC_MEMBER to build only a specific project/package. Meanwhile, rust-analyzer seems happy to work on any file from any of these projects in a single editor workspace.

There's a section in The Book on cargo workspaces: https://doc.rust-lang.org/book/ch14-03-cargo-workspaces.html (where this feature is about much more than just getting rust-analyzer to work with my preferred directory structure!)


Anyone else have thoughts on how best to structure your code and setup for working through something like The Book or any other materials for that matter?

5
 
 

For those on matrix but not aware of any rust spaces on there, here are some links to active rooms/spaces (courtesy of @[email protected] ):

https://matrix.to/#/#rust:mozilla.org

https://matrix.to/#/#rust:matrix.org

They're both part of this Space for Rust Matrix Rooms:

https://matrix.to/#/#rust-space:matrix.org (also the main link/url of the post)

In the rust-space you'll find a number of rooms specific to crates/libraries such as diesel and actix-web, and they seem active and open to helping people out with problems.

6
 
 

Welcome to week 4 of Reading Club for Rust’s “The Book” (“The Rust Programming Language”).

Starting today within the hour

"The Reading"

As we had some difficulty getting through the entire thing last week, this will be the continued reading of this section

Challenge this week

Rust Beginners Challenge - Write a file diff program [RUST] Instructions and an explination can be found in @[email protected]'s post here: https://sh.itjust.works/post/15301649

The Twitch Stream

7
 
 

Intro

So ... as we learn rust, exercises and puzzles are obviously valuable (at least in the early stages).

But IMO, jumping into just trying to write actually functional and useful programs can be very valuable.

I've been away for a bit and was wondering what I should do to start up rust learning again and figured that trying to power through some simple but not trivial program would be great. Then I figured people learning rust here might find the process worthwhile too.

The Idea of the Challenge

  • Pose a challenge in a post, outlining roughly what sort of program should be written, and at roughly what level it's pitched.
  • Propose a time period during which people can try to write the program, while having as much of a discussion as they like about it of course
  • When the time period is up, make another post inviting everyone to post where they got up to, posting code so we can discuss and provide feedback.

Any thoughts on this?

If you've got ideas for other challenges, feel free to post them. If there are a number of ideas it might be best to catalogue them and run them every week or month so as not to clog things.

The Challenge

A file diff program. Basically something like git diff or diff/colordiff.

git diff --no-index A B
  • Takes two files/paths as inputs, "A" and "B".
  • Determines the differences between them, or rather, what changes have been made to "B" relative to "A".
  • Changes are measured on a line by line bases (generally like git).
  • Provides some sort of output showing these changes.

Discussion

As I see it (not being an expert in this sort of program), there are three kinds of changes:

  • Addition
  • Deletion
  • Alteration

The difference between them depends, as far as I can understand right now, on whether lines surrounding the changed lines are duplicated in the reference file (file "A" lets say) and where they occur in the reference file relative to the changes.

I've got rough ideas about how this could work (which may be very wrong!) but I suspect working out the logic (if you haven't done it before) is a good part of the challenge as you then have to map that to rust.

We can talk about the logic in the comments here though, of course.

Also, an alteration here is really a deletion + addition, so not necessary, but it makes sense to me so I might try to implement it.

Otherwise, the output is open ended I'd say ... whatever makes sense to you. My first thought is JSON (which presents a chance to maybe try serde?). Something like:

[
  {
    "start_line_no": 0,
    "end_line_no": 1,
    "lines": ["this is a line of text", "and another"],
    "type": "unchanged"
  },

  {
    "start_line_no": 2,
    "end_line_no": 3,
    "lines": ["an added line",],
    "type": "addition"
  },

  ...
]

Probably a few complications there I haven't thought about, but you get the idea. You could even go further and supplement the program with a renderer that takes this JSON and produces HTML or something else.

Time

I'd say we can have a decent shot at this in a week. So how about I post again in a week asking how we all did.

8
1
submitted 1 year ago* (last edited 1 year ago) by [email protected] to c/[email protected]
 
 

Welcome to week 3 of Reading Club for Rust’s “The Book” (“The Rust Programming Language”).

Have a shot at going through “the reading” and post any thoughts, confusions or insights here “The Reading”

The Twitch Stream

Video Tutorial

Andy Balaam’s videos on PeerTube are great. For this section, see “Rust 101 - 3:Memory and ownership” makes a good companion piece. On PeerTube: https://diode.zone/w/1fEjNoHGUpwP8A2LgKxYLF

What’s Next Week?

Chapter 5 ... Using Structs to Structure Related Data Start thinking about challenges or puzzles to try as we go in order to get some applied practice!

  • EG, Advent of Code …
  • Maybe some basic/toy web apps such as a “todo”
9
1
submitted 1 year ago* (last edited 1 year ago) by [email protected] to c/[email protected]
 
 

I'll reply in the comments with a example of what lemmy sends for each thing you can do (I think I've thought of everything, but you can probably guess the format if not, or I can always add it).

So, the setup for these is:
Our instance is called 'local.com'
Our user is called 'freamon'
The other instance is called 'remote.com'
The community on that instance is called 'interesting'

For many of these, remote.com will receive them, and rewraps them in an Announce to send out to all the other instances with a copy of the community, so everyone stays in sync.

Sort by 'Old' for the best hope of these making sense.
I'll follow this post up with a script, that can be used to send these activities from the command-line, as I think it can help to understand Lemmy if you're using something much simpler than Lemmy to do some of things Lemmy does.

EDIT: As nutomic as mentioned, a better list is in the docs. It's the kind of thing I should read first, I guess.

10
 
 

Hi All!

Welcome to week 2 of Reading Club for Rust's "The Book" ("The Rust Programming Language").

Have a shot at going through "the reading" and post any thoughts, confusions or insights here

"The Reading"

Basically covering the fundamentals of the language before getting to grips with the borrow checker next chapter

The Twitch Stream

Video Tutorial

What's Next Week?

  • Chapter 4 ... Understanding Ownership
  • Start thinking about challenges or puzzles to try as we go in order to get some applied practice!
    • EG, Advent of Code ... I think @[email protected] is going to be running sessions on this on twitch? (Thursday 6.30pm EST (New York))?
    • Maybe some basic/toy web apps such as a "todo"
11
 
 

cross-posted from: https://diode.zone/videos/watch/9766d1f1-6018-48ec-ad67-e971758f8a3a

Going through some exercises on basic Rust syntax and ownership.

Links:

Rust 101 is a series of videos explaining how to write programs in Rust. The course materials for this series are developed by tweede golf. You can find more information at https://github.com/tweedegolf/101-rs and you can sponsor the work at https://github.com/sponsors/tweedegolf . They are released under the Creative Commons Attribution Share Alike 4.0 International license.

This series of videos is copyright 2023 Andy Balaam and the tweede golf contributors and is released under the Creative Commons Attribution Share Alike 4.0 International license.


These videos are roughly on track with the Reading Club apparently, so this video belongs here this week, I think.

12
 
 

cross-posted from: https://diode.zone/videos/watch/020c07e6-f124-4b3e-8270-cc2d21bf9c67

Continuing on Rust programming basics by looking at ownership and memory management, including the stack and the heap: what they are, how they differ, and why you need to care. > > For more help on ownership and the stack and the heap, try Chapter 4 of the Rust book. > > Links: >

13
 
 

This acts as a reminder that tomorrow Tuesday the 13th at 6:30 EST will be our second meeting, though you're welcome if it's your first time all the same. We'll be discussing what we've learned since last week, what we're doing this week coming, and reading the next two parts of The Book together. Along with that, we'll talk about a new (secondary and optional) stream possibly on Thursdays at the same time going through advent of code together in order to learn rust through code.

Hope to see you all there tomorrow but as always, the Vod will be available afterwards at the youtube channel listed in our Project Portal here: https://sh.itjust.works/post/14184272

14
 
 

Just a quick rundown of things happening here recently.

Getting Started

We got started! And definitely have some interest here already!

See, if you missed them:


First Reading Club

We had our first "Reading Club Meeting"! This was for reading through "The Book".

See, if you missed it:

Note also that there's a section in the sidebar for "Running Projects", basically any "series" of regular posts/cadences for a specific shared project. There's plenty of scope for more here ... let me know your thoughts!

I think us new to the language pretty quickly started wrestling with the ideas around the borrow checker (who would have thought!), which is also the part of the "official reading" for the next reading club!

This reading club has a twitch stream running in parallel (see https://www.twitch.tv/deerfromsmoke), on Tuesday's, 6.30pm EST (New York Time). If you can't make it then, videos will be on youtube and discussions will happen here of course.

Personally, I think the value of "study groups" or "workshops" or "reading clubs" is often forgotten. I was quickly reminded of that when just being in the twitch stream or reading a comment on the post got me compiling rust code. This community and the reading club has already helped me learn rust better/quicker!


Fediverse Friends

Turns out there's a nice video series on Rust over on PeerTube (fediverse youtube), which nicely parallels our rust reading club.

Even more nicely, PeerTube and lemmy federate with each other, which means you can subscribe to the channel through your lemmy instance and comment directly on the videos from lemmy! The channel should be available at [email protected] (this may require nudging your instance to get it to fetch the details, and, if none of the rust videos show up, may need to be searched specifically to force your instance to back fill).

See the channel on PeerTube here: https://diode.zone/w/p/xesbWmNanEHNBfJCZFQRUm (and the first post here: https://lemmy.ml/post/11655570).

The author, Andy, is also a subscriber here and is likely interested in any comments you have.

They posted here on how fediverse interop does work: https://mastodon.social/users/andybalaam/statuses/111906773513868731 (it's from mastodon but to this lemmy community and about their peertube account)


Recommended Rust Reading

For more experienced or confident rust programmers, having reading clubs for code bases or bigger/harder projects is probably a good idea.

We haven't got anything like that up and running, but we probably could and should.

To that end:

  • the rust crate/package for managing ActivityPub federation, employed by lemmy, was suggested (see GitHub Repo and post here)
  • The new lemmy API client re-written in rust (for the upcoming leptos front-end): see post here

Let me know if you're interested in having a regular reading group for such things!


Rust Practice Projects

Something that's been spoken about is starting to work together on projects or puzzles to practice our rust as we learn.

Advent of code with rust is one idea that may become a regular "series" here.

I'm sure there are others that you're interested in.

Personally, I'm thinking of just diving in and trying to make a basic "ToDo" web app with rust using Actix-web (web framework) and diesel (sql ORM in rust), both of which are used by lemmy, and some http template renderer. I'd probably stall pretty quickly but it's also such a common thing that fumbling around on it might be quite productive.

Anyone else interested in something like that as a regular/weekly series of posts for facilitating loosely collective work?

15
 
 

Will it happen again this week? Same day and time? Just curious.

16
 
 

The fediverse is working. I am now following (using Mastodon) a "Learning Rust" community on Lemmy [1], who I found through them commenting on my peertube video [2] using Lemmy.

[1] @learningrustandlemmy [2] https://diode.zone/w/wJJJ7DRh3fCvHq6KuZY3t9

#fediverse #rust #lemmy #peertube

17
 
 

An introduction to the Rust language basics.

What Rust is and why you might want to learn it
Examining a simple program
Learning about the types of variable you can have (numbers, strings, tuples, arrays)
Introducing control flow with if, for, while and loop
Talking about functions and expressions

Preparing ourselves for the next video, which is about memory management

If you'd like to learn more about Unicode and character sets, try my video Interesting Characters where I share how surprisingly interesting this whole area is.

Links:

Florian Gilcher on "Why Learn Rust?": https://youtu.be/l8Qk5Nh6qsg
Slides: http://artificialworlds.net/presentations/rust-101/A1-intro-to-rust
Exercises: https://101-rs.tweede.golf/A1-language-basics/mod.html

Rust 101 is a series of videos explaining how to write programs in Rust. The course materials for this series are developed by tweede golf. You can find more information at https://github.com/tweedegolf/101-rs and you can sponsor the work at https://github.com/sponsors/tweedegolf . They are released under the Creative Commons Attribution Share Alike 4.0 International license.

This series of videos is copyright 2023 Andy Balaam and the tweede golf contributors and is released under the Creative Commons Attribution Share Alike 4.0 International license.


This project is on-going, is hosted on PeerTube, and we aren't too far behind, so I thought it might be of interest.
Playlist so far: https://diode.zone/w/p/xesbWmNanEHNBfJCZFQRUm

18
 
 

Introducing the Rust 101 series and how to install Rust.

Rust 101 is a series of videos explaining how to write programs in Rust.

How to install Rust: https://rustup.rs/
Slides: http://artificialworlds.net/presentations/rust-101/0-intro
Exercises: https://101-rs.tweede.golf/0-install/mod.html

Follow the "Exercises" link to find the other tools you might want to install to follow along.

The course materials for this series are developed by tweede golf. You can find more information at https://github.com/tweedegolf/101-rs and you can sponsor the work at https://github.com/sponsors/tweedegolf . They are released under the Creative Commons Attribution Share Alike 4.0 International license.

This series of videos is copyright 2023 Andy Balaam and the tweede golf contributors and is released under the Creative Commons Attribution Share Alike 4.0 International license.

Duration: 9min 44sec


This project is on-going, is hosted on PeerTube, and we aren't too far behind, so I thought it might be of interest.
Playlist so far: https://diode.zone/w/p/xesbWmNanEHNBfJCZFQRUm

19
 
 

General page for the Rust for Lemmings Reading Club.

All relevant links and posts should be collected here (go to specific discussion posts for discussion).

Also, a link to this "Portal", and any others, should be in the sidebar for easy access.

General Structure of the Reading Club:

A good companion set of materials to use are @[email protected] 's videos over on PeerTube (fediverse youtube).

Week 1

Week 2

Week 3 - Ownership and the borrow-checker

Week 4

...

20
 
 

Hi All! Welcome to the Reading Club for Rust's "The Book" ("The Rust Programming Language"). This is week 1 (the beginning!!).

Have a shot at going through "the reading" and post any thoughts, confusions or insights here

"The Reading"

The Twitch Stream

What's Next Week?

  • Chapters 3 and 4
  • Start thinking about challenges or puzzles to try as we go in order to get some applied practice!
    • EG, Advent of Code
    • Maybe some basic/toy web apps such as a "todo"
21
 
 

I think the fist meet up when well and covered some nice ground. Learning about the match statement for flow of control feels like a cool idea that I hope to experiment with more in my own learning projects.

22
 
 

I threw together a rust client for lemmy to play a similar role to the lemmy-js-client. I figure it's a good candidate for this community to look at since it's both fairly simple and covers all the API endpoints.

23
1
submitted 1 year ago* (last edited 1 year ago) by [email protected] to c/[email protected]
 
 

Streamed Code Together

A streamed reading club focused on rust's The Book and becoming reasonably good rust developers through community collaboration. The end goal is to read the lemmy codebase and contribute to the platform we all love. This stream will serve as a club meeting where we read some of the content together, discuss previous topics, and write some code.

Anybody's welcome, whether you want to continue once we get to the code base or not. If you're completely new to rust this is a great place to start and if you already know the language we'd love to have you all the more. At the very least it's a good networking opportunity but you'll likely learn more than you thought.

Post Stream

After the stream, a discussion post will be made to This Community stating what we've gone over and what we're planing to read/code/do before the next stream. This will act as a place to talk about what you've learned, what issues you're having, how your post-stream learning is going, and to help your fellow lemmings. I strongly encourage posting a comment even if everything you've stated has already been said.

Timing

We will meet weekly at 6:30pm EST (New York Time) on Tuesday with a maximum length of two hours.

Hosting

For now, the host will be myself however if you're interested in hosting or co-hosting yourself please feel free to message me about this especially if you can stream at a time where people in a European or Asian timezone can join in.

Missed the stream?

A video will be available on youtube so you can watch at a later point and a discussion post will be posted here weekly which states what we've gone over and what we're going to do before the next stream.

Links

The weekly stream will be hosted on twitch with that site being our main chatroom. Vods will be available on Youtube after the stream along with a mildly edited version for those who couldn't join in but still want to keep up

Twitch: https://www.twitch.tv/deerfromsmoke

Youtube Playlist: https://www.youtube.com/playlist?list=PL5HV8OVwY_F9gKodL2S31czb7UCwOAYJL

Our Learning Rust and Lemmy Community: [email protected]

Original Post: https://sh.itjust.works/post/13993219

24
 
 

Running Test Instances

The question has come up of running a test instance under a domain such that it could federate with other instances over the internet.

See, eg, MxRemy's comment and the thread that follows: https://lemmy.ml/comment/7984848

We don't want to pollute the network

The issue is that we might "pollute" the federation network with our instances that won't do much and are likely to be short-lived or intermittent. If you don't know, managing how a lemmy instance reacts to other instances that have gone silent or failed to reply/receive a request is a thing. AFAIU, the general idea is you don't want to give up on an instance ... timeouts and downtimes happen ... but how do you know when to actually just give up? Most lemmy instances are likely still pinging instances/domains that went dark ages ago.

Our own closed/local federation

A work around though could be to run our test instances in "allowlist federation" mode. IE, they only federate with specified domains.

See the docs on this: https://join-lemmy.org/docs/administration/federation_getting_started.html?highlight=allowlist#federation


Should there be interest in this ... we could have a simple list of domains here (linked in the sidebar too) from people running their test instance and eager to poke and prod federation. When you setup your own test instance, you can then just run in allowlist mode and copy the list from here.

25
 
 

The library has a nice guide and two working examples, so I tried the local_federation example. To build the example, you need Rust compiler, cargo package manager, and git:

$ git clone https://github.com/LemmyNet/activitypub-federation-rust
$ cd activitypub-federation-rust
$ cargo run --example local_federation axum
[INFO  local_federation] Start with parameter `axum` or `actix-web` to select the webserver
[INFO  local_federation::axum::http] Listening with axum on localhost:8001
[INFO  local_federation::axum::http] Listening with axum on localhost:8002
[INFO  local_federation] Local instances started
[INFO  local_federation] Alpha user follows beta user via webfinger
[INFO  activitypub_federation::fetch] Fetching remote object http://localhost:8002/.well-known/webfinger?resource=acct:beta@localhost:8002
[INFO  activitypub_federation::fetch] Fetching remote object http://localhost:8002/beta
[INFO  activitypub_federation::fetch] Fetching remote object http://localhost:8001/alpha
[INFO  local_federation] Follow was successful
[INFO  local_federation] Beta sends a post to its followers
[INFO  local_federation] Alpha received post: Hello world!
[INFO  local_federation] Test completed

You may want to use network analizyer (e.g, wireshark) to see how it works under the hood.

GET /.well-known/webfinger?resource=acct:beta@localhost:8002 HTTP/1.1
accept: application/jrd+json
digest: SHA-256=[redacted]
signature: keyId="http://localhost:8001/#main-key",algorithm="hs2019",[...]
host: localhost:8002

HTTP/1.1 200 OK
content-type: application/json
content-length: 269
date: Sat, 03 Feb 2024 23:05:19 GMT

{
  "subject": "acct:beta@localhost:8002",
  "links": [
    {
      "rel": "http://webfinger.net/rel/profile-page",
      "type": "text/html",
      "href": "http://localhost:8002/beta",
      "template": null
    },
    {
      "rel": "self",
      "type": "application/activity+json",
      "href": "http://localhost:8002/beta",
      "template": null
    }
  ]
}

[...]
view more: next ›