Skip to content

Instantly share code, notes, and snippets.

View alexxbb's full-sized avatar

alexxbb

  • Graphics Tools Engineer @ NVidia
  • Vancouver, Candada
View GitHub Profile
@alexxbb
alexxbb / dyn_trait_generic.rs
Created January 11, 2022 22:56
Downcast trait object to generic concrete type
#![allow(unused)]
use std::any::Any;
use std::marker::PhantomData;
struct NumericAttr<T> {
_m: PhantomData<T>,
}
impl<T> NumericAttr<T> {
@alexxbb
alexxbb / mpmc.rs
Created November 8, 2021 21:27
An example of mpmc with flume crate
// This will spawn 2 producer threads which will try to keep up to NUM_SESSIONS Sessions available for consumers
use flume::Receiver;
use once_cell::sync::OnceCell;
#[derive(Debug, Clone)]
struct Session;
const NUM_SESSIONS: usize = 10;
@alexxbb
alexxbb / rust_rayon.rs
Created March 4, 2020 04:25
Rust rayon example
// Parallel iterator over a contiguous array of i32 values given a raw pointer and size;
use rayon::prelude::*;
fn var_1(ptr: *mut i32, len: usize) {
// With a stdlib slice
let data_sl = unsafe { std::slice::from_raw_parts_mut(ptr, len) };
data_sl.into_par_iter().for_each(|i| *i *= *i);
}