Acute Accent
46 minutes ago

✍️ New watchexec-focused cohost page and a big recap + story of the recent Watchexec releases:
#rust #rustlang

josh 💽
4 hours ago

It's pretty rough and ready, but here's a Rust app I wrote up quickly that you can run and it will go through and unfollow accounts that aren't following you back. Seems to work. I may clean it up a bit later and add features, but for now. Let's ship it!

#Rust #Mastodon #API #Coding

Brian Dorsey
4 hours ago

#rustlang folks up for a question?

I tried to convert a .fold() into a .reduce(), but it didn't work and I don't understand why. Math on shared references to ints seems to work in .fold, but not in .reduce?

fn main() {
let v = vec![1, 2, 3, 4];

// works
println!("{:?}", v.iter().fold(0, |acc, e| e + acc));
// fails: expected `&{integer}`, found integer
println!("{:?}", v.iter().reduce(|acc, e| e + acc).unwrap());
// changing to .into_iter() works


6 hours ago

🦀 Mixing C++ and Rust for Fun and Profit: Part 1 | KDAB

#Rust #Cpp

any advice for good error handling in #rust :rust:

8 hours ago

I feel like the #rust compiler is gaslighting me...

10 hours ago

Yesterday I was in for a day of pain (but a lot of learning) when trying to implement graphs in #Rust. Interesting read about that topic:

Loki the Cat
10 hours ago

Linus Torvalds discussing maintainers, AI, and Rust in the kernel. Ah, the joys of being a cat God of mischief. Maintainer fatigue? More like napping fatigue. 😼 And aging in the kernel community? No worries, we bring in young kittens like Rust! Meowtainers, assemble! 🐱💻 #Linux #Rust #CatGodOfMischief

10 hours ago

Ok so I PERSONALLY am not saying that you should subscribe to my #YouTube channel for amazing #Rust #Golang #NixOS and general #DevOps #livecoding videos ...

But I think this person is 😅

We are at 988 subscribers right now, do you wanna be one of the last 12 we need to make it to 1000? 🙏

10 hours ago

One of my favourite things about #rust is how easy it is to refactor, and I think I've managed to steal some of that for Spade.

Today I realized I had misunderstood how CSI lanes work. They are merged almost right away, not at the end when reading pixel data. That's a pretty fundamental difference, but it turned out that my code was quite easy to transform from one to the other. It worked pretty much on the first try after re-compiling.

I don't think that would have been the case in #verilog

Martin Geisler
12 hours ago

When teaching #rust, I often see people have a "Wow 🤯!" experience when I show #rustdoc #doctest system: you write small pieces of Rust code in your documentation and they are then executed as part of your test suite.

What people often don't know is that this system is ancient! I first met in #python and there it was introduced in 1999: That's 24 years ago!

I don't know if this was the first implementation of this concept?

Shenzi Thinker Abouter
12 hours ago

i'm crying i can't develop in the rust playground because the playground's filesystem is out of space

I was working on the advent of code ;-;

#rust #rustlang

René Dudfield
13 hours ago

Data structures in #rust - "it depends"

graph TD
    A[Data Structure Decision] --> B{Is Order Important?}
    B -- Yes --> C{Are Duplicates Allowed?}
    B -- No --> F{Is Fast Lookup Required?}
    C -- Yes --> D[Use Vec<T> or LinkedList<T>]
    C -- No --> E[Use HashSet<T> or BTreeSet<T>]
    F -- Yes --> G[Use HashMap<K, V> or BTreeMap<K, V>]
    F -- No --> H{Is Data Homogeneous?}
    H -- Yes --> I[Consider Array<T; N> or Tuple]
    H -- No --> J[Consider Custom Data Structure]
Paweł Grzybek
13 hours ago

This is probably the least idiomatic example of a Rust code ever, but I just finished my solution for Advent Of Code day 4. Catching up and fighting borrow checker :) Tons of fun tho!

#aoc #rust

René Dudfield
13 hours ago

Memory management in #rust - "it depends".

graph TD
    A[Start: Memory Management Decision] --> B{Is Data Shared Among Multiple Owners?}
    B -- Yes --> C{Does Data Have Compile-Time Fixed Size?}
    B -- No --> H[Use References]
    C -- Yes --> D{Is Mutability Required?}
    C -- No --> G[Use Rc<T> or Arc<T> for Reference Counting]
    D -- Yes --> E[Use Mutex<T> or RwLock<T> with Arc<T>]
    D -- No --> F[Use Box<T> for Heap Allocation]
    H --> I{Is Data Exclusively Owned?}
    I -- Yes --> J[Use Box<T> for Heap Allocation]
    I -- No --> K[Use Borrowing with &T or &mut T]

I've brought back support for animated sprites in Kludgine and #Gooey, and wired everything up to the work-in-progress TileMap widget. #Rust #RustLang

René Dudfield
14 hours ago

Error handling in #rust - "it depends".

graph TD
    A[Error Handling in rust - 'It depends'] --> B{Is the Error Recoverable?}
    B -- Yes --> C{Is a Value Optional?}
    C -- Yes --> D[Use Option<T>]
    C -- No --> E[Use Result<T, E>]
    B -- No --> F{Should the Program Continue?}
    F -- Yes --> G[Implement Custom Error Handling]
    F -- No --> H[Panic and Abort Execution]
Caleb Maclennan
14 hours ago

A few days ago somebody poked me about monster repos causing pathologically long run times for `git-warp-time`. A lot of fiddling and a couple releases later v0.7.0 is now about 300× faster. Not 300 percent, 300 times faster!

There is probably one more order of magnitude left on the table with some careful memory caching and threading, but over two orders of magnitude faster is a good start.

#rustlang #rust #git

What's a good tutorial or resource I can follow to learn myself some Rust by giving it max 2h a week?

Edit: if you have tips to get started with a vim setup I'd love them as well (using ALE for everything lint/lsp)

#rust #programming

Dan Leech
16 hours ago

I find myself creating an uncomfortable and worrying number of new git packages recently, and it's a chore.

7 years ago I created Skeletor to bootstrap them:

Is there anything new/old in this space, preferably in #Golang or #Rust?

@prma That clicks for me. I've been diving into OCaml over the past few months, and really enjoying it. I'm doing this year's #AdventOfCode in OCaml and looking at incorporating it into a couple of other projects.

Some impressions so far:

- The core language is pretty tight. Much of what looks like syntax (such as the `|>` or `<-` operators) are simply defined in libraries through the core function definition syntax.
- There are two main "dialects" of note: the `Stdlib` library that is available by default, and a wholesale replacement for `Stdlib` by Jane Street, `Core` (and its lighter subset, `Base`). It can be confusing at first when looking at documentation or examples that would work with the one but not with the other.
- OCaml has all the type safety of a language like Rust, but the incredibly powerful type inference means that you seldom need to annotate variables or functions with their type. This can lead to really compact, readable code that almost looks like pseudocode.
- This compactness, combined with a really mature toolchain (`dune`, `ocamllsp`, `utop`) leads to a very speedy feedback loop when prototyping. I find myself testing out ideas in the `utop` REPL before coding in my LSP-enabled editor. While you write a piece of code, the LSP's type checker constantly gives feedback on correctness. I find the "click" when the type checker is suddenly happy delightful. More often than not, once I run the code it just works.
- "Expect tests" are a wonderful prototyping tool that allow you to "eyeball" output until it looks right, and then capture it as a formal regression test – and as in-test documentation of the expected output for a given test case. I love it.
- In terms of "dialect", my personal preference is for the Jane Street libraries, which have extensive functionality and are battle-tested in a very demanding production environment.

The biggest downside to learning #OCaml vs. #Rust is that it's hard to find and filter the right information. The ML languages have been around for decades, and advice from 15 years ago might not apply to your current libraries. There is no equivalent to the "Rust Book" that gives you the definitive, comprehensive overview of the language. The closest is "Real-World OCaml" ( which is specific to the Jane Street libraries. I can highly recommend it.

Francis ☑️
17 hours ago

In #rust when you have a hashmap and want to insert or modify an entry, there's a pattern where you chain .and_modify().or_insert().

If you are inserting a complicated new entry, you might want to define the new entry first in one place, and then insert it, but closure move rules interfere.

Any way to define (a,b,c) once?

let hashmap = HashMap::<Vec<(A, B,C)>>::default();
let new_entry = (a, b, c);
hashmap.entry(z).and_modify(|e| { e.push( new_entry ) }).or_insert(vec![new_entry]);

Thomas Koeppen
17 hours ago

test-log is a crate that takes care of automatically initializing logging and/or tracing for Rust tests. Yeah, we can remove our own init_logger() from each individual test. #rust #tests

17 hours ago

#adventofcode 2023 day 9 in #rust

Using Binomial coefficient and Pascal's triangle. Day 1 to 9 still under 1 millisecond in total! 🚀

Part 1 in 0.042 ms (42 μs):

Part 2 in 0.042 ms (42 μs):

Day 1 to 9 in 0.59 ms (parallel: 0.31 ms)

I actually like my naive implementations better, but a bit slower. Efficient with an array on the stack, and reusing it for counting.

Naive in 49 μs and 53 μs:

18 hours ago
18 hours ago

🚀 Building a Better Foundation for Rocket's Future - Rocket Web Framework

「 Along with the release of Rocket v0.5, today I'm sharing plans to launch the Rocket Web Framework Foundation, or RWF2. The RWF2 is a nonprofit organization designed to support Rocket and the surrounding ecosystem, financially and organizationally 」

#RocketFramework #Rust #Opensource

So i guess i'm learning a bit more about traits and polymorphism in #Rust by making my code care less about the exact type of numbers it gets, at least in the utility functions (still had to make that choice in main).

It's certainly very hacky as i was experimenting with how to make the compiler happy, rather than how people do things, but that's how i learn, i'll probably read that part of the rust book now 😅 .

Lord Olle W
18 hours ago

Lucka 9 - Game state

Årets julkalender från Agical är en spelmakarstuga där vi skriver ett shoot'em'up-spel i programmeringsspråket Rust och spelramverket Macroquad. Idag fortsätter vi med lucka 9. I denna lucka blir det lite faktorisering genom att vi lägger till ett så kallat "game state" som gör att vi kan pausa spelet och få en startmeny.

#rust #RustLang #gamedev #game #programmerinf #Adventskalender #macroquad #spel #spelutveckling

Ett datorfönster med lila bakgrund, olika stora gröna fyrkanter, en gul cirkel och tre små vita cirklar på rad. Nere i vänstra hörnet står texten ”Poäng: 4711”. I mitten står det ”Pausat”. Nere till höger är en bild av Ferris the Rustacean med tomteluva och spelkontroller. Överst är texten ”Spelmakarstuga från Agical”.

Given a Datastructure like this:

pub struct Thread {
// contains all messages of a thread
pub messages: Vec<Message>,
// contains the messages as a tree structure
pub root: &Message

pub struct Message {
pub children: Vec<Message>

I know I need to add lifetime annotations. But is it possible to model a similiar data structure w/o using Rec<RefCell<Message>>? It feels like cheating.

#rust #rustlang

Alghost :godot:
20 hours ago

I just completed "Mirage Maintenance" - Day 9 - Advent of Code 2023 #AdventOfCode

Had a quick stumble with an infinite loop because I didn't change my input sequence. Then I noticed the input contained negative numbers, which required some tricky modifications to my nom parser. Afterwards there was an integer overflow (fixed using i64). Other than that, my solutions for both parts worked immediately. ⭐✨

Solutions in #Rust can be found here:

Andy Smith
21 hours ago

"A Rust implementation of Android's Binder"

An actual useful #Linux kernel device driver (re)written in #Rust. When this gets upstreamed, there will be production Rust code in the majority of Linux devices on Earth, as it will be in every (in-support) Android phone.

22 hours ago

I already loved the rust compiler and the tooling around it, but after a few days of doing #adventofcode in #rust , I'm even more impressed by how good they have become.

Giving #HelixEditor a try as well.
Fumbling with the keybinds, but I wish #vim was this snappy (and required so little config).

#rustlang #aoc2023

Shenzi Thinker Abouter
1 day ago

released pict-rs 0.4.6 today.

big change is a new internal endpoint for preparing for the 0.5.0 upgrade

#rustlang #rust

Michael Friedrich 🦊
1 day ago

🎯 Release speed-run

#GitLab 16.6, GitLab Duo Chat Beta
Parca v0,28.0, @opentelemetry Collector v1.0.0/v0.90.0, @Prometheus v2.48.0, @PromOperator 0.70.0
Wireshark 4.2.0, #Rust 1.74.0

Jan :rust: :ferris:
1 day ago

This thing will (probably) blow up 🚀

mfio - Framework for #Async I/O Systems:

"mfio is a one-stop shop for custom async I/O systems. It allows you to go wild, beyond typical OS APIs.[...]"

- Async
- Automatic batching (vectoring)
- Fragmentation
- Partial success
- Lack of color (full sync support)
- I/O directly to the stack
- Using without standard library

#Rust #RustLang #RustAsync #AsyncRust #Memflow #IO

Andrew Lilley Brinker
1 day ago

It is so deeply weird to me that this group would write and submit a public document defending C++ to an RFC that includes as a core priority supporting the move away from memory unsafe languages, and then wouldn't sign their names.

All but one other response to the RFC, 105 total, is a named organization, a named individual or individuals, or has no name field filled out and minimal content.

Theirs is the only semi-professional submission which is explicitly "anonymous"

#rust #rustlang

Jan :rust: :ferris:
1 day ago

@bobulous You might be able to squeeze some additional performance:

- use #[inline] on small methods that are executed often (in parsers on methods like "next_token")

- use `lto = fat` in your Cargo.toml (⚠️ increases build times)

There is more - have a look at this excellent book by @nnethercote

#Rust #RustLang #Performance

1 day ago

#AdventOfCode Day 8 - part 2 was A LOT of luck, as in "mayyyyybe the input works that way" and it was definitely a shot in the dark, with a side of "a harder version would be day 15, not day 8" -

#AoC2023 #rust #rustlang #cheeeeese

Andrew Lilley Brinker
1 day ago

Aha! They refer to themselves as the “ISO C++ Directions Group” which appears to be the group that authored P2000r4 and P2759r0, namely:

- Howard Hinnant
- Roger Orr
- Bjarne Stroustrup
- David Vandevoorde
- Michael Wong

#rust #rustlang

1 day ago

If there’s any #rust #pyo3 people willing to help a smooth brain write a wrapper library, any and all help would be greatly appreciated

@kubikpixel I'm using #Helix for #Rust programming and I love it. If you're going to give Helix a try then definitely follow the built-in tutorial first by typing (on the command line):

hx --tutor

And make sure to install the rust-analyzer tool so that Helix can highlight errors and warnings each time you save. Can be tricky to get the pieces to work together at first, but on re-reading the online instructions it becomes clear eventually.

Phew, had me worried for a minute. I'm writing a simple XML 1.0 parser in #Rust just for practice, and on feeding it a 4.4MB XML file it took 56.5s to read it. I've done nothing to optimise it yet, but even so that sounded dire.

Then I remembered to use "release" mode, and the time dropped to 3.9s. Whatever the compiler is doing behind the scenes, I'll take that 14x speed boost, thank you.

#RustLang #Compilers #XML

1 day ago

Day 10 and 11 of #100DaysOfRust

I'm getting deeper and deeper into the #Rust programming language and learning different ways to implement functions and for what reason. Oh, if I didn't get far in the course yesterday.
I also thought about developing with a #Vim clone on #RustLang, this is #Helix. I also found out about libraries that I might use in the future 🦀

#100daysofcode #learn

René Dudfield
1 day ago

It's really cool, but also a bit weird to me doing a #linux kernel training using #rust at microsoft. 90s me probably wouldn't believe C was still being used. I can see some good ergonomic improvements and statically checking things like reference counting. I have used static checkers for reference counting in C with the CPython API via a compiler plugin, but I'm not sure it is as "sound" as the rust for kernel abstractions. The linux driver future seems joyful.

Andrew Lilley Brinker
1 day ago

They don’t name themselves. It’s unclear if this is an official ISO C++ response.

Their response tries to muddy what safety means, argues a strawman about Rust having vulnerabilities too, suggests “profiles” for C++ should fix everything anyway, hints thah C++ critics are actually just talking about old C++ (in the same breath they argue that C++ is great because it’s always stable so old code sticks around forever), and that really you should give C++ more money.

#rust #rustlang

Andrew Lilley Brinker
1 day ago

lol, a group of unnamed “C++ senior members with decades [of] experience in ISO C++” filed a response to the federal RFI on open source software security and it is ridiculous.

#rust #rustlang

Thomas Frans 🇺🇦
1 day ago

General #Rust wisdom:

If a crate promises things that sound like magic, you're about to be drowning in generics and traits.

Yes I would like a `T: Stream + Partial + StreamIsPartial, <T as Stream>::Token: AsChar, <T as Stream>::Slice: ParseSlice<O>, O: UInt` thank you very much. Perfectly normal and not confusing at all function signature.

I'm not complaining. I understand that in order to get this magic to work, you need to be generic. Just having a laugh at some silly function signatures.

Alex Nedelcu
1 day ago

I've fallen a little behind on my Rust ports, due to $work and family obligations.

#AdventOfCode #AdventOfCode2023 #Rust

I'm live!

I'm a bit late, spent way too much time on my makeup...
Anyways, we'll be continuing work on the ECS and hopefully finishing this wretched world off >:3

Well... uhhh finishing the world structure hehe :3

#rust #rustlang #twitch #stream #goinglive

2 days ago

Nakago, my alpha #Rust API framework, has been updated with Axum v0.7 and Hyper v1.0! I'm excited to see the ecosystem around Hyper mature as it gains broader adoption. 🚀

Cindʎ Xiao 🍉
2 days ago

You can take this a step further and write a script that automatically extracts all of this panic location metadata, in your reverse engineering tool of choice. I wrote a quick Binary Ninja script that goes and extracts all panic location metadata, finds the locations in the code where they are referenced, and then annotates each location with a tag that displays the extracted source file information. Here are the tags generated by my script, run on a piece of Rust malware targeting macOS systems, RustBucket.

(I like having the scream emoji everywhere 😱)

#rust #rustlang #ReverseEngineering #MalwareAnalysis

A screenshot of Binary Ninja's Tags view showing tags for panic locations in a Rust binary, including file paths, line numbers, and column numbers, with the line "library/std/src/sys/unix/thread_parking/ line 51, col 9" highlighted. A scream emoji is used to annotate all tags.
Cindʎ Xiao 🍉
2 days ago

Note that this location information is only embedded into Rust binaries if the developer uses the default panic behaviour, which unwinds the stack, cleans up memory, and collects information to show in the panic message and in backtraces. You can read more about the details of the default panic implementation in the Rust standard library in the Rust Compiler Dev book.

Developers can trivially strip the location information by just putting panic = 'abort' when specifying the build profile in their Cargo.toml build configuration file; this will cause the program to immediately abort on panic instead, without taking any further actions. Developers can also provide their own custom panic handlers - you can learn more about this in my previous post about the panic handlers used by the Rust code in the Windows kernel, here:

Of course, a lot of Rust malware out there doesn't even bother taking the more basic step of stripping symbols, much less this panic information... 😉

#rust #rustlang #ReverseEngineering #MalwareAnalysis

Cindʎ Xiao 🍉
2 days ago

Compare the above snippet of source code with the decompiler's output, at one of the locations where this particular core::panic::Location struct is referenced. We can see the following arguments all being passed into the function sub_18001ee90, which is the entry point to the panic handling logic (notice how the branch where that function is called is also noreturn).

1) The fixed error message for the unreachable!() macro (internal error: entered unreachable code)

2) The length of that error message string (0x28 characters)

3) The address of that core::panic::Location struct.

} else {
sub_18001ee90("internal error: entered unreachable code", 0x28, &panic_location_"library\std\src\sys\windows\")
uint64_t n_6 = n * 2
if (n_6 u>= 0xffffffff) {
n_6 = 0xffffffff
n_2 = n_6

The information passed in the arguments is used to construct the message that the program emits when it panics, which in this case will look something like the following:

thread 'main' panicked at 'internal error: entered unreachable code', library\std\src\sys\windows\

We can also see several other features which appear in the original source code at this location:

1) The check of the GetLastError() result against the ERROR_INSUFFICIENT_BUFFER error code.

2) The saturating multiplication of the variable n.

#rust #rustlang #ReverseEngineering #MalwareAnalysis

Cindʎ Xiao 🍉
2 days ago

Because the Rust standard library is open-source, we can actually go read the source code at the place that this core::panic::Location data points to. The Rust compiler and standard library live in the same Git repository (rust-lang/rust) and are released together; the last piece of information we need to find the source code here is the Git commit ID of the Rust compiler / standard library version that was used to create this binary.

This is something we can find by examining some of the other strings in this binary, which contain paths like this, which have the rustc commit ID embedded inside them:


We can now look up the exact location in the source code: rust-lang/rust commit 8ede3aae, File library\std\src\sys\windows\, Line 252 (0xfc), Column 17 (0x11):

fn fill_utf16_buf<F1, F2, T>(mut f1: F1, f2: F2) -> crate::io::Result<T> {
if k == n && c::GetLastError() == c::ERROR_INSUFFICIENT_BUFFER {
n = n.saturating_mul(2).min(c::DWORD::MAX as usize);
} else if k > n {
n = k;
} else if k == n {
// It is impossible to reach this point.
// On success, k is the returned string length excluding the null.
// On failure, k is the required buffer length including the null.
// Therefore k never equals n.
unreachable!(); // ⬅️ This is the location from our binary!
} else {

This is indeed a place where the code can panic! The unreachable!() macro is used to mark locations in the code that should never be reached, in cases where reachability cannot be automatically determined by the compiler. The documentation for unreachable!() says:

This will always panic! because unreachable! is just a shorthand for panic! with a fixed, specific message.

#rust #rustlang #ReverseEngineering #MalwareAnalysis

Davy :ferris:
2 days ago

When unsafe Rust is very unsafe... and angry :ferris: (spotted near Howth Harbour, Ireland - a month ago)

#rust #rustlang

Restaurant sign with "CRABBY JO'S" written on it.
Evan Hahn
2 days ago

"One way of describing the history of programming languages over the past 75 years is: They have steadily raised the baseline of what 'normal' programmers can express in their languages."

#programming #coding #ProgrammingLanguages #Rust

Joshua Byrd 🎄
2 days ago

I thought I might try blogging some kind of Rust tutorial alongside learning it myself. So anyway here's the first of a series if you wanna follow along. Just a simple Hello World!

#Rust #RustLang #Tutorial #Blog #Programming

Thorsten Leemhuis (acct. 1/4)
2 days ago

The @LWN articles on this years #Linux #kernel maintainers summit are now freely available:


* Trust in and maintenance of #filesystems.

* Committing to #Rust / #Rustlang for kernel code

* Reducing kernel-maintainer burnout

* A discussion on kernel-maintainer pain points

Side note: if you wonder who the #LinuxKernel developers in below picture are, checkout this page:

picture from
Elan Hasson
2 days ago

@zkat use FUD to get #rust.

Elan Hasson
2 days ago

@zkat add buffer overflows to code and publish RCE CVE PoCs and management will let you rewrite in #rust

Shane Celis
2 days ago

Rust has a mini-game, actually it has many mini-games: kill the clone(), keep it &str, and DON’T collect(). On the don't collect() side, one often wants to keep things as an iterator if possible. But there are obstacles to writing functions that return iterators rather than collections. For instance suppose I have a function that I want to conditionally return an iterator a or b. I can't do a simple `if c { a } else { b }` but here's a way to make it work. #rust

Rust code showing how to conditionally return an iterator without restorting to collect().
Tom Schouten
2 days ago

Back to #rustembedded after crawling out of the #embedded C swamp.

I learned #zig basics and refreshed my #rust, just to see them side by side. Rust is intimidating, isn't it? Zig's simplicity is compelling.

I have a dynamic typing habit, and Zig's comptime is a lure. But as my brain ages I do feel that Rust's type system is probably the more responsible choice.

If you have the time to learn Rust, it's probably time well spent. But it is not simple.

As for Zig. Definitely worth a look!

I've been working towards supporting popup menus, tooltips, modals, and other "layered" interface elements in #Gooey. Here's a short video demoing the OverlayLayer widget. #Rust

3 days ago

#Rust moment

let result = handle.await.unwrap().unwrap().unwrap().unwrap();