1076
15
Rust Analyzer Changelog #199 (rust-analyzer.github.io)
1077
25
1078
30
1079
20
submitted 3 years ago by modulus@lemmy.ml to c/rust@programming.dev

Hi there,

I'm working on a bot to do social games on the fedi, and using the mastodon-async crate for communicating with the ActivityPub server in question. At the moment I'm using tokio mt as a runtime, though I'm new at async so if you think I shouldn't let me know.

The pattern I want to implement is the following:

  • At any given time, a user sends a "play" message to the bot.
  • If the player list is empty, the player is added to it awaiting someone else.
  • Otherwise, the bot checks if there are enough players on its list (who have previously sent a play message). For some games, enough is 1, since it's a 2-player game, for some it's 3 or more.
  • If there are enough players, play commences. list is cloned for that match, then emptied so other players can get in.

What I'm not very clear is how to keep this list to assure that sequence will be respected. I.a., if two play messages come reasonably quick together, I want one to be processed, then entered on the list, or get the match to start; then the other to get processed.

My current thoughts:

  • I could use a channel that receives the player accounts. When a new player is added, it performs the logic.
  • I could use a mutex with a list (or an option player value for the degenerate case of 2-player games).

Any thoughts on what the reasonable thing to do is here? I'm very new to async and while I realise there's probably lots of ways to do this, they're not all equally ergonomic and I want to avoid myself future pain.

1080
41
1081
50
submitted 3 years ago by derivator@feddit.de to c/rust@programming.dev

You can play the game at oort.rs. I've found it quite addictive so far. The link in the post is a writeup of the most recent tournament results in the single fighter category, which seems to be the main category being played at the moment. I think now is a good time to get into it as no one has perfected a strategy yet and even the first place AI still crashes into the arena walls sometimes. 😅 There is an active discord server (yeah, I know 😬) with a small but nice community :)

1082
27
submitted 3 years ago* (last edited 3 years ago) by snaggen@programming.dev to c/rust@programming.dev

If you are using Rust for web or considering doing so, you might be excited to hear that rustls merged a PR to make ring an optional dependency. Soon(-ish) you will be able to choose which cryptography backend to use with rustls, including one written fully in Rust. That would help with making your projects easier to build. Big thank you to rustls team, including Joe Birr-Pixton, @djc, and @cpu!

https://github.com/rustls/rustls/pull/1405

1083
21
The Embedded Rustacean Issue #2 (www.theembeddedrustacean.com)
submitted 3 years ago* (last edited 3 years ago) by apollolabsbin@programming.dev to c/rust@programming.dev

The Embedded Rustacean Issue #2 is Live. RSS Feed has also been made available. https://www.theembeddedrustacean.com/p/the-embedded-rustacean-issue-2

1084
29
submitted 3 years ago by eraclito@feddit.it to c/rust@programming.dev

I think some raised points are relevant...

1085
8
This Week in Rust #512 #rustlang (this-week-in-rust.org)

This Week in Rust #512 #rustlang

1086
-2

⚡ NEW LET'S CODE EPISODE ⚡

@ematipico joined @JoshuaKGoldberg and @IanVS to talk about what it's like to maintain @biomejs a @rust based
@TypeScript zero-config linter and formatter that's lightning fast.

Welcome to the future!

https://youtu.be/cGHCdqnT05Q

What other other projects would you like to see a Let's Code for? Anything that has a particularly well run community or particularly cleanly run GitHub?

1087
12
This Week in Rust 512 (this-week-in-rust.org)
1088
11
1089
79
1090
13

Forgot to announce that we've released This Month in Rust GameDev for July 2023 a couple of weeks ago!

In the meantime, we've already started putting together August news for the 49th issue. Please join: https://github.com/rust-gamedev/rust-gamedev.github.io/issues/1440

1091
22

This 3-day conference by & for the #rustlang community will begin with an add-on workshop day, followed by two days of talks and an unconference day on Friday. Learn more and register to join us remotely: https://rustconf.com/

1092
11
1093
23
Rust Analyzer Changelog #198 (rust-analyzer.github.io)
1094
14
submitted 3 years ago* (last edited 3 years ago) by snaggen@programming.dev to c/rust@programming.dev

TL;DR - Use std::slice::Chunks when you'd like to measure a slightly more accurate execution time of each future in a big batch of futures.

1095
52
1096
44
submitted 3 years ago by fil@programming.dev to c/rust@programming.dev
1097
22
My Node.js is a bit Rusty (gal.hagever.com)
submitted 3 years ago by javasux@lemmy.world to c/rust@programming.dev

Replacing an internal Node.js module with a native Rust module made a x25 perf boost. Let’s understand why.

1098
51
1099
28
1100
-1
submitted 3 years ago* (last edited 3 years ago) by nerdblood@programming.dev to c/rust@programming.dev

The first post had a couple errors that made things confusing. I have an accurately formatted JSON response, but I still can't seem to deserialize it.

I keep getting an error where the response isn’t matching up as expected: Error("data did not match any variant of untagged enum NationResponse"

I have a JSON response that looks like this:

 {
      {
            "id": 1,
            "country": "usa"
        },
        [
            {
                "id": 1,
                "age": 37,
                "name": "John"
            },
            {
                "id": 2,
                "age": 21,
                "name": "Nick"
            },
        ]
}

And I’m trying to deserialize it, but I can’t seem to get it right. Isn’t this accurate?

#[derive(Deserialize, Debug)]
#[serde(untagged)]
enum NationResponse {
    Nation(Nation),
    People(Vec),
}

struct Person {
    id : i32,
    age : i32,
    name : String
}

struct Nation {
    id : i32,
    country : String
}

Edit:

The problem I was actually experiencing was trying to use an enum as the response. Yes the formatting for my example was wrong (it should have been an array). But the structure besides that was accurate.

What I needed was Vec>

view more: ‹ prev next ›

Rust

8252 readers
30 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

!performance@programming.dev

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 3 years ago
MODERATORS