Rust

8237 readers
24 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
1
 
 

I've been trying to contribute to statrs recently, and one of the issues I've been running into is that I'm trying to have an iterator that returns items in sorted order without cloning the underlying data. I'm working this PR if you wanted to take a look at my code so far. I looked up this problem and found this StackOverflow post about this topic from years ago but, frankly, I don't believe it. Assuming you're iterating from a vector, mutating the underlying vector is akin to keeping state on the order of the vector. Why cant that happen in a separate data structure? Is there a more efficient way to represent ordinality other than a vector? Creating an iterator is simply tracking traversal through that structure, which I think could be done using a bloom filter to track which indices have not been traversed yet. That just leaves the traversal algorithm itself. What information would an iterator need to know to make the best decision? Could I adapt a sorting algorithm to be an iterator?

I'm asking a lot of questions because I'm a statistics guys, not an algorithms guy. Any starting point or input is much appreciated!

2
 
 

If you recently used Cargo, make sure your system didn't get infected. Here is another article with a little more info: https://www.stepsecurity.io/blog/arrayref-rust-crate-supply-chain-attack

3
4
5
6
7
8
 
 

scholium::mark annotation replaces all kinds of TODOs with Rust-native way, allowing developers to categorize them with better precision, write better reasoning and make them easy to extract, report and maintain in the long run. Thanks to Rust literal string boundaries, it's possible to write long multiline reasons, for example allowing to attach even code snippets if needed.

Annotation is made to be attached to an exact place and it provides only documentation value without altering an item attached in any way. This means if the annotation when be attached to a function, module, crate (or a statement), it documents this particular item and nothing else.

#[scholium::mark(
    info,
    implementation::extend,
    doc::possible_extensions,
    reason = "Extend functionality to use any type implementing `+` operation"
)]
fn add(a: u32, b: u32) -> u32 {
    a + b
}
9
 
 

I guess Goish might be hated by many Rust fans and Go fans. Anyway, below is the example taken from its website.

use goish::{go, KB};
use goish::sync::WaitGroup;

#[goish::main]
fn main() {
   let wg = &WaitGroup::new();
   wg.Add(1_000_000);

   for i in 0..1_000_000 {
       // Explicit 2 KiB stack, sub-page allocated from the >chunked
       // stackpool - the opt-in for extreme spawn density. >Everyday
       // code just writes go!(move || ...) and never sizes a >stack.
       go!(stack(2 * KB), move || {
           do_work(i);
           wg.Done();
       });
   }

   wg.Wait();
}
10
11
 
 

IMPORTANT: i dont reccommend you read through my code here. feel free to reach out for clarity on the details.

id like to investigate about rewriting my "decentralized p2p encrypted messaging app" in Rust. if you are familiar with any of the details, id like to hear your opnions on the approach.

my project is complex and would carry a significant overhead to redo in Rust. the core reason behind investigating rust is that it has better tooling for things like formal-verification. in general it seems like a better language for a project like mine. as a webdev, it was easy enough for me to put together and while i can use things like tauri to build for native, i think dioxus's approach for a native build is good.

im aiming to create something fairly unique for "secure messaging". i created a prototype (without AI) for my project to share and discuss. it demonstrates the core-concept around client-side managed secure cryptography in javascript.

https://github.com/positive-intentions/chat

javascript doesnt have a great reputation in the cryptography communities and its always a struggle to promote, so it was important for it to be open source. im proud of the work there, but i see details i overlooked. this led me to creating a new version to fix the outstanding issues. (it was things like handling key-rotation, group-messaging, etc).

https://positive-intentions.com/blog/introducing-enkrypted-chat

the MVP version lacked things like unit-tests, while the second-iteration not only had unit-test, but armed with AI, i was able to do things like create audits and formal-verification. the whole project is absurdly complicated and not worth your time to review. things like audits and formal-proofs/verification are fundamentally invalid because i used AI to create it. the attempt is genuine and i found the process educational, but cybersecurity and cryptography is specialized and has countless nuances to consider. it isnt worth your time to debug my code.

i now i think the project could benefit from being rewritten in Rust. its a much more suitable and respected language for what im trying to do, but i have never used rust to do something of this scale. i expect it will carry a huge learning curve given my background as a webdev.

https://github.com/positive-intentions/whatsup

creating a webapp for me is easy enough, but my project relies on some core technologies which i want supported on all platforms consistently. some core things i need to consider:

  • webrtc - its the core data-channel for my project. im sure that as a webapp it can be done... it might be a stretch to build a wasm to bridge to JS if nessesary, but im sure it can work. i would also like rust to build for other architectures. i think the support is also reasonable for the native build, but i wonder it there could be issues for a CLI version.
  • Module federation - in the browser-based version im using module-federation and its working as exected. it particularly helps to separate functionality, which is generally a good approach for a complex project. in Rust's cargo file, it seems i could add something like `foo_crate = { git = "https://github.com/MyOrg/foo/_crate"}`. that seems like it would also limit how i handle close-source details of the project
  • local-only storage - a core detail to my app is that it works p2p without registration. there are no databases of registered users. in a pwa i can use various forms of storage provided by the browser. i would like to use an approach that is consistent in rust to avoid bespoke code for different platforms (easier maintainance).\
  • ui framework - im using dioxus for far, but its largely AI slop... its could just as easily be leptos (im still investigating comparing the two)... but if i really think outside the box... i wonder how difficult it would be to use webcomponents from rust. i was working on a webcomponent framework and it would be interesting to seem if there would be a performance advantage to using something closer to vanillajs. webcomponents probably are not a good idea if i want better support between platforms.

maybe there are other details i should keep in mind? i think i will have to create multiple creates for things like UI components library and p2p-framework (similar to how i did it for the javascript version)

thanks for reading this far. have a nice day.

12
13
14
15
16
17
18
19
20
 
 

geteilt von: https://programming.dev/post/54554551

iceoryx2 provides zero-copy inter-process communication mechanisms based on shared memory and data structures that are modified concurrently by multiple processes.

One of the key operations in these algorithms is a memory copy using core::ptr::copy. However, this results in undefined behavior if one process reads the data while another process writes to it concurrently. Even if our lock-free algorithm reliably detects such a race, iceoryx2 cannot depend on undefined behavior in a safety-critical system.

This blog post introduces our solution: a byte-wise atomic wrapper that enables well-defined concurrent copy operations. It also shows how it can be used to implement a simple sequence lock.

Note: I am not the original author of the blog post. Since the author does not have a programming.dev account, I am posting it on her behalf.

21
22
 
 

Palette isn't forgotten or abandoned. I have just been doing other things for a bit and some of the new additions needed more time in the oven than usual. Either way, here's finally the latest version. You can read all about the changes in the announcement post, so I will not repeat them here, but let me know if there are any thoughts or questions. I will do my best to answer.

Enjoy!

23
24
25
 
 

Hey, I'm a webdev. I previously approached the project with JavaScript. I'm familiar with the js ecosystem.

I put a fair bit of consideration and in contrast to my JavaScript-approach, I'd like to investigate Dioxus.

I'm not completely new. I've dabbled in rust before. I have read a lot of the docs and I'm sure there is much more to learn amd practice. I also don't want to downplay that I'm ai-slop-maxxing at scale.

What advice would you give to getting started with the rust ecosystem approach?

Similar to a lot of languages there are considerations for things like tests. So it would be useful to see the options there. As well as any other best-practices and nuances.

In relation to my project, I'm particularly interested in the tooling available in rust for formal verification.


Just to be clear, im not here to waste your time on my slop, but if you want to see what I've got so far (practically nothing):

view more: next ›