#rust
✍️ New watchexec-focused cohost page and a big recap + story of the recent Watchexec releases: https://cohost.org/watchexec/post/3818997-watchexec-library-3
#rust #rustlang
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! https://github.com/phocks/mastodon-automations
#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
}
🦀 Mixing C++ and Rust for Fun and Profit: Part 1 | KDAB
https://www.kdab.com/mixing-c-and-rust-for-fun-and-profit-part-1/
any advice for good error handling in #rust :rust:
Coastal Concrete
Moody skies suit the harsh concrete shore.
#landscapephotography #coast #waterways #rust #shoreline #waves #cumbria #clouds #lakedistrict #sea #water #metalwork #monochrome #landscape #blackandwhitephotography #photography #abstract #photographer #railings #concrete #bleak #structures



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: https://github.com/nrc/r4cppp/blob/master/graphs/README.md
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

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
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: https://groups.google.com/g/comp.lang.python/c/DfzH5Nrt05E/m/Yyd3s7fPVxwJ. That's 24 years ago!
I don't know if this was the first implementation of this concept?
This year I've been really enjoying #AdventOfCode solution blogs by
@geekyaubergine : https://zoeaubert.me/tags/advent-of-code/ : #Rust #Rustlang
@robb : https://rknight.me/blog/tags/adventofcode/ : #PHP
@lewis : https://lewisdale.dev/post/tag/advent-of-code-2023/ : #Typescript
Eric Burden : https://www.ericburden.work/categories/advent-of-code-2023/ : #Kotlin
@neilnjae : https://work.njae.me.uk/tag/advent-of-code/ : #Haskell
Who else is writing great explanations of their solutions? Help me find new people.
(I write #Python solutions at https://hamatti.org/adventofcode/2023)
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!
I've brought back support for animated sprites in Kludgine and #Gooey, and wired everything up to the work-in-progress TileMap widget. https://youtu.be/tfLWHtFuWCo #Rust #RustLang
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.
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)
#AdventOfCode day 9 https://github.com/Balise42/AoC2023/blob/main/src/day09.rs nothing much to say today!
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: http://dantleech.github.io/skeletor/
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" (dev.realworldocaml.org) which is specific to the Jane Street libraries. I can highly recommend it.
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]);
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
https://crates.io/crates/test-log
#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): https://github.com/timvisee/advent-of-code-2023/blob/master/day09a/src/main.rs
Part 2 in 0.042 ms (42 μs): https://github.com/timvisee/advent-of-code-2023/blob/master/day09b/src/main.rs
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: https://github.com/timvisee/advent-of-code-2023/blob/master/day09a/src/bin/naive.rs
видеодневник-2, продолжительность — 19 секунд: https://invidious.protokolla.fi/watch?v=Yk9mtDTIsZE ⦾ https://www.youtube.com/watch?v=Yk9mtDTIsZE #videojournal #adornment #windows #garlands #rust #grids #bars #MW
🚀 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 」
https://rocket.rs/v0.5/news/2023-11-17-rwf2-prelaunch/
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 😅 .
https://codeberg.org/tshirtman/advent_of_code_2023/src/branch/main/src/day9.rs
Here is the article/blog post for my talk at #H2HC today: https://rcvalle.com/blog/2023/12/09/llvm-cfi-and-cross-language-llvm-cfi-support-for-rust/
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.
https://macroquad-introduktion.agical.se/ch8-game-state.html
#rust #RustLang #gamedev #game #programmerinf #Adventskalender #macroquad #spel #spelutveckling

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.
I just completed "Mirage Maintenance" - Day 9 - Advent of Code 2023 #AdventOfCode https://adventofcode.com/2023/day/9
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:
https://github.com/lemilonkh/adventofcode23/tree/main/day9/src
"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.
https://lwn.net/SubscriberLink/953116/29637cca929c2fdc/
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).
released pict-rs 0.4.6 today.
https://git.asonix.dog/asonix/pict-rs/releases/tag/v0.4.6
big change is a new internal endpoint for preparing for the 0.5.0 upgrade
🎯 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
This thing will (probably) blow up 🚀
mfio - Framework for #Async I/O Systems:
https://github.com/memflow/mfio
"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
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"
@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")
https://nnethercote.github.io/perf-book/inlining.html
- use `lto = fat` in your Cargo.toml (⚠️ increases build times)
https://nnethercote.github.io/perf-book/build-configuration.html#link-time-optimization
There is more - have a look at this excellent book by @nnethercote
#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" - https://github.com/Balise42/AoC2023/blob/main/src/day08.rs

@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.
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 🦀
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.
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.
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.
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.
I've fallen a little behind on my Rust ports, due to $work and family obligations.
https://github.com/alexandru/advent-of-code/blob/main/rust/2023/day7/src/main.rs
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
https://twitch.tv/ciubix8513
#rust #rustlang #twitch #stream #goinglive
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. 🚀 https://github.com/bkonkle/nakago/discussions/76
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 😱)

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: https://infosec.exchange/@cxiao/110500609127711155
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... 😉
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 {
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
sub_18001ee90("internal error: entered unreachable code", 0x28, &panic_location_"library\std\src\sys\windows\mod.rs")
noreturn
}
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\mod.rs:252:17
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
.
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:
/rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225\\library\\alloc\\src\\vec\\mod.rs
We can now look up the exact location in the source code: rust-lang/rust
commit 8ede3aae
, File library\std\src\sys\windows\mod.rs
, 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!
becauseunreachable!
is just a shorthand forpanic!
with a fixed, specific message.
Postgres Language Server: implementing the Parser
https://supabase.com/blog/postgres-language-server-implementing-parser

"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." https://v5.chriskrycho.com/journal/wizardry-frontier/
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! https://josh.is-cool.dev/2023-12-7-nature-keeps-evolving-rustaceans/
The @LWN articles on this years #Linux #kernel maintainers summit are now freely available:
https://lwn.net/Articles/951847/
Topics:
* 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:

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

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. https://youtu.be/ylpIBVFo6jI #Rust