Skip to content

Instantly share code, notes, and snippets.

View AurevoirXavier's full-sized avatar
🌊
Rusting

Xavier Lau AurevoirXavier

🌊
Rusting
View GitHub Profile
[Rule]
DOMAIN, inv.cafe, DIRECT
DOMAIN, aihubmix.com, DIRECT
PROCESS-NAME, Motrix, DIRECT
Verify Github on Galaxy. gid:LHCK8DuK6QLFzsaqEhK2rR
@AurevoirXavier
AurevoirXavier / [Rust] write_to_shared_memory_from_multiple_threads.md
Last active June 23, 2022 01:02
[Rust] Write to shared memory from multiple threads

I'm having some trouble trying to figure out how to share mutable data between threads.

I have a Vec I want multiple threads to write to simultaneously. I don't care if the threads tries to write to the same index (data races are allowed in this context).

How do I go about doing this?

@AurevoirXavier
AurevoirXavier / [Rust] Objects with Reference to Self and Lifetime Subtyping.rs
Last active May 14, 2020 02:55
[Rust] Objects with Reference to Self and Lifetime Subtyping
use std::collections::HashMap;
type Handler<'a> = Box<dyn Fn(i32) -> i32 + 'a>;
pub struct Router<'r> {
routes: HashMap<String, Handler<'r>>,
}
pub struct RouteAdder<'a, 'r: 'a> {
router: &'a mut Router<'r>,
@AurevoirXavier
AurevoirXavier / [Rust] Confusing Error E0499.rs
Last active April 8, 2020 06:14
[Rust] Confusing Error E0499
#[allow(unconditional_recursion)]
fn bar<'a>(data: &'a mut Vec<&'a u8>) {
bar(data);
bar(data);
}
// ---
#[allow(unconditional_recursion)]
fn bar<'a>(data: &'a mut Vec<&u8>) {
@AurevoirXavier
AurevoirXavier / [Rust] Confused About Lifetimes.rs
Last active April 8, 2020 06:14
[Rust] Confused About Lifetimes
struct Test {
x: i32
};
let a;
{
let b = &Test { x: 42 }; // Temporary struct Test put on the stack
a = b;
} // Temporary Test dropped here?
@AurevoirXavier
AurevoirXavier / [Rust] Lifetime of Reference in HashMap.rs
Last active April 8, 2020 06:13
[Rust] Lifetime of Reference in HashMap
struct Cheese<K1, K2, V> {
things: HashMap<K1, V>,
refs: HashMap<K2, &V>
}