Skip to content

Instantly share code, notes, and snippets.

View pacmancoder's full-sized avatar
🇺🇦

Vladyslav Nikonov pacmancoder

🇺🇦
View GitHub Profile
@pacmancoder
pacmancoder / Q&A.md
Created October 21, 2020 17:03
Rust FAQ

This example shows how to pass rust closure as C callback without need of Box type (nostd; no liballoc); Created for the the implementation of thread::spawn for FreeRTOS (rust-idf)

Only requirement - malloc and free functions

@pacmancoder
pacmancoder / compile_time_type_generation_with_trait_requirements.rs
Created September 16, 2019 12:52
Compile-time type generation with trait requirements
use std::marker::PhantomData;
struct Unconcrete;
struct One;
struct Two;
struct Three;
struct Four;
struct Five;
@pacmancoder
pacmancoder / 01_rust_xtensa_atomics.md
Last active December 25, 2019 13:43
Rust-Xtensa atomics support workarround

USE ON YOUR OWN RISK

WARNING

  • Files, lsited in this gist are generated (except generation script itself)
  • Tested only partially
  • GCC compiller from Xtensa toolchain is required to make this code work.
  • Or instead you can generate static library with the GCC once and link it to the rust code
@pacmancoder
pacmancoder / A.md
Created August 23, 2019 10:59
Pocket Chip
@pacmancoder
pacmancoder / owned_singleton.rs
Created August 20, 2019 06:46
Rust Discovery Initiative
use core::sync::atomic::{ AtomicU32, Ordering };
struct Part {
val: u32,
}
struct Data {
a: Part,
b: Part,
}
@pacmancoder
pacmancoder / unsafe_test.rs
Created October 25, 2018 16:46
Exploring unsafe in rust
extern crate rayon;
use rayon::prelude::*;
use std::marker::PhantomData;
use std::mem;
struct Storage<'a, T : 'a>
{
ptr: *mut T,
phantom: PhantomData<&'a T>,
@pacmancoder
pacmancoder / poc.rs
Last active October 23, 2018 22:08
[Rust] Overlaying Slices iterator PoC
extern crate rayon;
use rayon::prelude::*;
struct State<'a>
{
first: &'a [usize],
other: &'a mut [usize],
value: Option<(&'a [usize], &'a mut [usize], &'a [usize])>,
}
@pacmancoder
pacmancoder / RwLockProxy.cpp
Last active February 20, 2018 15:34
Read-Write lock proxy for any type
/* Vladislav Nikonov [2018]
*
* This class represents read-write lock proxy for any type. Writer always have higest
* entrance priority (e.g. if object was already locked by readers - no new readers allowed before
* writer exit from lock.
*/
#include <mutex>
#include <shared_mutex>
#include <chrono>
/* Vladislav Nikonov [2018]
*
* Template visitor implementation, which will wait for concrete visitor dispatch,
* and will throw on other events. This can be done by method overload based on template type.
* This method will be overriden by function call, provided by client code
*/
#include <iostream>
#include <memory>
#include <vector>