Sidebar

Rust

rust
Rust martinn 4 days ago 100%
I made a tool to aggregate git blame stats across any repo github.com

I've always been curious about this. If I were to take a snapshot of a git repo at a particular point in time, who would be the top contributors by active lines of code? And then, what type of files have they contributed the most? So I built this little tool. I've been wanting to learn rust for quite some time now and this was one of my first projects in it. It was a lot of fun! It uses `git` under the hood to obtain the information and it's nothing fancy, but keen to hear what you think.

17
1
rust
Rust xameer 6 days ago 100%
#rust analyzer question for #emacs folks

[\#rust](https://mathstodon.xyz/tags/rust) analyzer question for [#emacs](https://mathstodon.xyz/tags/emacs) folks In client more I see run and debug But gui emacs I don't .. why pfa [@rust](https://programming.dev/c/rust)

7
1
rust
Rust thevoidzero 1 week ago 94%
[Help] Is there a way to detect all structs in the current crate that implement a certain trait?

Hi all. I want to develop a plugin system within my program, and I have a trait that functions defined by plugins should implement. Currently, my code gets all the functions in a HashMap and then calls them by their name. Problem is, I have to create that hashmap myself by inserting every function myself. I would really appreciate it if there was a way to say, suppose, all pub members of `mod functions::` that implement this `trait PluginFunction` call `register(hashmap)` function. So as I add more functions as `mod` in `functions` it'll be automatically added on compile. Pseudocode: Files: ``` src/ ├── attrs.rs ├── functions │   ├── attrs.rs │   ├── export.rs │   └── render.rs ├── functions.rs ├── lib.rs ``` Basically, in `mod functions` I want: ``` impl AllFunctions{ pub fn new() -> Self { let mut functions_map = HashMap::new();[[ register_all!(crate::functions::* implementing PluginFunction, &mut functions_map); Self { function_map } } } ``` Right now I'm doing: ``` impl AllFunctions{ pub fn new() -> Self { let mut functions_map = HashMap::new();[[ crate::functions::attrs::PrintAttr{}.register(&mut functions_map); crate::functions::export::ExportCSV{}.register(&mut functions_map); crate::functions::render::RenderText{}.register(&mut functions_map); // More as I add more functions Self { function_map } } } ```

17
10
rust
Rust _hovi_ 2 weeks ago 100%
World Wonders Explorer - small Leptos site demoing a free API I built

Hey all, just sharing a small, single-page site I built using Leptos + TailwindCSS, mainly intended as a demo for an API I built using Axum. Hope someone also finds it interesting! I'm sharing this site and not the API itself cause I figure it's easier to look at and understand, but if you want to roast some code I would appreciate any feedback you have on the API itself (repo [here](https://github.com/Rolv-Apneseth/world-wonders-api)). Trying to leave the front end developer scene so this is the first API I've tried building, fairly basic but it was fun (I am a big Civ V fan - I hear it's inspired by some niche thing called human history?). Edit: whoops, looks like the link didn't get set cause I put an image - the site is available [here](https://explorer.world-wonders-api.org), and the repo for it is [here](https://github.com/Rolv-Apneseth/world-wonders-explorer). The live API is available [here](https://www.world-wonders-api.org/v0/docs#model/apikeylocation)

16
2
rust
Rust kia 2 weeks ago 100%
Derailed talk regarding Rust's integration into the Linux filesystem https://www.youtube.com/watch?v=WiPp9YEBV0Q

In case you haven't seen it, here's a talk regarding Rust's integration into the Linux filesystem that gets completely derailed at The Linux Storage, Filesystem, Memory Management and BPF Summit.

30
2
rust
Rust fil 2 weeks ago 100%
Asterinas linux abi compatible OS core in Rust https://asterinas.github.io/

After reading Drew's [pitch to the rust community](https://drewdevault.com/2024/08/30/2024-08-30-Rust-in-Linux-revisited.html) to write our own kernel, I've searched for "linux abi compatible rust kernel" and found "Asterinas". Surprised that it is not mentioned here

25
4
rust
Rust chevy9294 2 weeks ago 100%
XHTML 1.0 Transitional parser?

So I'm trying to parse school's website for some info. I'm trying to get some values using xpath. So I found a html 5 parser and it can't properly parse the first line. Then I figure you it's actually XHTML and not HTML. After quick Google search I found out XHTML can be properly parsed using any XML parser and so I found one and... It can't parse the first line. So I ask LLama3.1 (like a real programmer) why I can't parse the first line with any parser. It explained so nicely that I did not destroy my keyboard when I was told that this document is "XHTML 1.0 Transitional" and it's a mix of HTML 4 and XHTML and can't be parsed with HTML nor XML parser. I hate the guy that invented that so much... So I can't find a crate to parse XHTML 1.0 transitional? Or a crate to convert xhtml to something else? Any advice?

4
7
rust
Rust secana 4 weeks ago 100%
What are you working on this week? (Aug. 25, 2024)

Hi rustaceans! What are you working on this week? Did you discover something new, you want to share?

25
11
rust
Rust Flexaris 4 weeks ago 83%
Flashing custom FTDI board

I'd like to know if anyone has succesfully flashed a board using their own FTDI chip and not a commercial debug probe. I want to get into using Rust and I have these STM-based boards where I put an FTDI chip on them so I get a convenient USB-port for power and debug and flashing. I'd really like to get some Rust-software running but I've just hit walls so far with flashing the boards. They work fine when using platformio/openocd and C++ but nothing has worked so far for using "cargo embed" even though it seems to find the FTDI chip correctly and start flashing but then times out. I'd love to know if anyone has a similar setup working or can give tips on what I could try.

4
0
rust
Rust tengkuizdihar 1 month ago 85%
Treedome 0.5.0: Local Encrypted Notes with Modern Features codeberg.org

cross-posted from: https://programming.dev/post/18265389 >Hello again everyone, Dihar here. It's been a while since the last release of treedome, but here you go! This release is all about UI update, emojis, and bug fixes. Please consult this `git diff` for a more detailed changelog https://codeberg.org/solver-orgz/treedome/compare/0.4.5...0.5.0. These are the highlight of the release. > > ![](https://programming.dev/pictrs/image/a452c1ee-634e-4f63-b462-1733817bac52.png) > > * Add emoji picker for title, will show up in tree! > * Text Editor toolbar is back, now with option to toggle both toolbar and floating menu independently! > * Checkbox is here! Thanks Mantine UI! > * You can check the size of each notes by navigating to Escape Menu -> Configure -> Show Note Sizes! > * Add created/last modified date in notes. Note created before this will not have this field and will set as today's date! > * Create child note can now be done through dropdown instead of only from shortcuts! > * Fix bugs of saving empty tree > * General UI update and more stability for auto scrolling in tree view > * Documentation update

15
0
rust
Rust absolutely_vivid 1 month ago 100%
Building a Multithreaded TUI With Rust and Cursive https://absolutely-vivid.srht.site/blog/multithreaded-tui-with-rust

I wrote a quick blog post about a pattern I discovered while building TUI applications in Rust. It's a bit unrefined, and I'm working on package to help make the pattern easier. Let me know what you think!

19
1
rust
Rust Doods 1 month ago 70%
Debug-time enforcement of borrowing rules, and safety in general.

Another crazy idea I share with this website. I was developing a game and an engine in Rust, so I was reading many articles, most of which criticize the 'borrow checker'. I know that Rust is a [big agenda language](https://youtu.be/TH9VCN6UkyQ?si=MJBBA9t1K2UrmfZ4&t=215), and the extreme 'borrow checker' shows that, but if it weren't for the checker, Rust would be a straight-up better C++ for Game development, so I thought: "Why not just use `unsafe`?", but the truth is: `unsafe` is not ergonomic, and so is `Refcell<T>` so after thinking for a bit, I came up with this pattern: ``` let mut enemies = if cfg!(debug_assertions) { // We use `expect()` in debug mode as a layer of safety in order // to detect any possibility of undefined bahavior. enemies.expect("*message*"); } else { // SAFETY: The `if` statement (if self.body.overlaps...) must // run only once, and it is the only thing that can make // `self.enemies == None`. unsafe { enemies.unwrap_unchecked() } }; ``` You can also use the same pattern to create a `RefCell<T>` clone that only does its checks in 'debug' mode, but I didn't test that; it's too much of an investment until I get feedback for the idea. This has several benefits: 1 - No performance drawbacks, the compiler optimizes away the `if` statement if `opt-level` is 1 or more. (source: [Compiler Explorer](https://godbolt.org/)) 2 - It's as safe as `expect()` for all practical use cases, since you'll run the game in debug mode 1000s of times, and you'll know it doesn't produce `Undefined Behavior` If it doesn't crash. You can also wrap it in a "safe" API for convenience: ``` // The 'U' stands for 'unsafe'. pub trait UnwrapUExt { type Target; fn unwrap_u(self) -> Self::Target; } impl<T> UnwrapUExt for Option<T> { type Target = T; fn unwrap_u(self) -> Self::Target { if cfg!(debug_assertions) { self.unwrap() } else { unsafe { self.unwrap_unchecked() } } } } ``` I imagine you can do many cool things with these probably-safe APIs, an example of which is macroquad's [possibly unsound](https://github.com/not-fl3/macroquad/issues/333) usage of `get_context()` to acquire a `static mut` variable. Game development is a risky business, and while borrow-checking by default is nice, just like immutability-by-default, we shouldn't feel bad about disabling it, as forcing it upon ourselves is like forcing immutability, just like Haskell does, and while it has 100% side-effect safety, you don't use much software that's written in Haskell, do you? Conclusion: we shouldn't fear `unsafe` even when it's probably unsafe, and we must remember that we're programming a computer, a machine built upon chaotic mutable state, and that our languages are but an abstraction around assembly.

7
26
rust
Rust armchair_progamer 1 month ago 100%
graydon/rust-prehistory: historical archive of rust pre-publication development github.com

Excerpt: > This is a reconstruction -- extracted and very lightly edited -- of the "prehistory" of Rust development, when it was a personal project between 2006-2009 and, after late 2009, a Mozilla project conducted in private. > > The purposes of publishing this now are: > > - It might encourage someone with a hobby project to persevere > - It might be of interest to language or CS researchers someday > - It might settle some arguments / disputed historical claims Rust started being developed 18 years ago. This is how it looked until 14 years ago, where I believe the rest of development is on [rust-lang/rust](https://github.com/rust-lang/rust/commits/c2d4c1116f96463b8af222365d61d05bc42a78ac/?after=c2d4c1116f96463b8af222365d61d05bc42a78ac+34). The [first Rust program](https://github.com/graydon/rust-prehistory/blob/b0fd440798ab3cfb05c60a1a1bd2894e1618479e/test/foo.rs) looks completely different than the Rust we know today.

43
1
rust
Rust ericjmorey 1 month ago 94%
A table of publicly available Arena crates and their features https://donsz.nl/blog/arenas/

[Table of Arena Crates](https://donsz.nl/blog/arenas/) For a technical discussion of using arenas for memory allocation with an example implementation, see gingerBill's [Memory Allocation Strategies - Part 2: Linear/Arena Allocators](https://www.gingerbill.org/article/2019/02/08/memory-allocation-strategies-002/)

17
0
rust
Rust Timely_Jellyfish_2077 1 month ago 96%
Which is more important for rust compilation: higher number of cores or faster single core performance?

Planning to build a PC in couple of weeks. What is the optimal number of cores to have without having diminishing returns?

25
6
rust
Rust abrahambelch 1 month ago 100%
Strategy Pattern in Rust

Hey there, I'm currently learning Rust (coming from object-oriented and also to some degree functional languages like Kotlin) and have some trouble how to design my software in a Rust-like way. I'm hoping someone could help me out with an explanation here :-) I just started reading the book in order to get an overview of the language as well. In OOP languages, I frequently use design patterns such as the Strategy pattern to model interchangeable pieces of logic. How do I model this in Rust? My current approach would be to define a trait and write different implementations of it. I would then pass around a boxed trait object (`Box<dyn MyTrait>`). I often find myself trying to combine this with some poor man's manual dependency injection. This approach feels very object oriented and not native to the language. Would this be the recommended way of doing things or is there a better approach to take in Rust? Thanks in advance!

29
19
rust
Rust ericjmorey 1 month ago 100%
Understanding Rust's Trait Objects: Vtables, Dynamic Dispatch, and Memory Deallocation https://www.eventhelix.com/rust/rust-to-assembly-tail-call-via-vtable-and-box-trait-free/

EventHelix writes: > This article will investigate how Rust handles dynamic dispatch using trait objects and vtables. We will also explore how the Rust compiler can sometimes optimize tail calls in the context of dynamic dispatch. Finally, we will examine how the vtable facilitates freeing memory when using trait objects wrapped in a `Box`.

18
0
rust
Rust chevy9294 1 month ago 86%
What watches can run Rust?

Maybe a little weird question but do you maybe know a smart watch that can run rust? I got running Egui on my Galaxy Watch 4 with WearOS and I'm thinking if any other watch (other than Galaxy and Pixel) can do that?

11
7
rust
Rust BB_C 1 month ago 100%
COSMIC ALPHA 1 Released (Desktop Environment Written In Rust From System76) https://system76.com/cosmic

[archived link](https://web.archive.org/web/20240808155545/https://system76.com/cosmic)

71
8