Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View DutchGhost's full-sized avatar

DutchGhost DutchGhost

View GitHub Profile

Keybase proof

I hereby claim:

  • I am dutchghost on github.
  • I am dutch_gh0st (https://keybase.io/dutch_gh0st) on keybase.
  • I have a public key ASAwDqevj5i8sQ7FdR3wH7lTOZrWKhSXNeN6Zxb_7UE-Vgo

To claim this, I am signing this object:

Keybase proof

I hereby claim:

  • I am dutchghost on github.
  • I am dutch_gh0st (https://keybase.io/dutch_gh0st) on keybase.
  • I have a public key ASAwDqevj5i8sQ7FdR3wH7lTOZrWKhSXNeN6Zxb_7UE-Vgo

To claim this, I am signing this object:

@DutchGhost
DutchGhost / atoi.rs
Created September 21, 2018 16:23
Atoi with exact_chunks
#![feature(exact_chunks)]
const POW10_U64: [u64; 20] = [
10_000_000_000_000_000_000,
1_000_000_000_000_000_000,
100_000_000_000_000_000,
10_000_000_000_000_000,
1_000_000_000_000_000,
100_000_000_000_000,
10_000_000_000_000,
use std::cell::RefCell;
trait Defer {
fn call(self: Box<Self>);
}
impl<F: FnOnce(T), T> Defer for (F, T) {
fn call(self: Box<Self>) {
(self.0)(self.1);
}
use crate::{
container::container::{Container, scope},
fundemental::{range::Range, proof::NonEmpty, index::Index},
};
pub fn qsort<T: Ord>(slice: &mut [T]) {
scope(slice, |mut v| {
if let Ok(range) = v.range().nonempty() {
quicksort(&mut v, range);
}
@DutchGhost
DutchGhost / indexing.rs
Created April 7, 2019 20:13
Typed indexing
#![feature(nll)]
use std::marker::PhantomData;
// Can't make it longer or shorter
#[derive(Copy, Clone)]
struct Invariant<'id>(PhantomData<*mut &'id ()>);
impl<'id> Invariant<'id> {
pub const fn new() -> Self {
use std::marker::PhantomData;
use std::ops::{Deref, DerefMut};
/// Fake stdlib's TraitObject:
/// https://doc.rust-lang.org/std/raw/struct.TraitObject.html
/// That requires nightly, but this works on stable.
#[derive(Copy, Clone)]
#[repr(C)]
struct TraitObject {
_data: *mut (),
@DutchGhost
DutchGhost / debub.rs
Created May 16, 2019 18:54
debugstruct using const generics
#![allow(dead_code, unused_variables)]
#![feature(const_generics)]
pub type uinfo = u32;
pub struct Debug<T, const LINE: uinfo, const COLUMN: uinfo> {
pub inner: T,
}
impl <T, const LINE: uinfo, const COLUMN: uinfo> Debug<T, {LINE}, {COLUMN}> {
@DutchGhost
DutchGhost / const_digits10.rs
Last active May 29, 2019 20:33
Digits10 at compiletime
#![feature(const_generics)]
struct Range {
start: usize,
end: usize,
}
impl Range {
pub const fn new(start: usize, end: usize) -> Self {
Self { start, end }
@DutchGhost
DutchGhost / unreachable.rs
Created June 11, 2019 18:57
stable unreachable function
#![no_std]
#[inline]
pub const unsafe fn fake_type<T>() -> T {
hint_unreachable()
}
#[inline]
pub const unsafe fn hint_unreachable() -> ! {
fake_type()
}