Skip to content

Instantly share code, notes, and snippets.

@hlb8122
hlb8122 / view_types.rs
Last active March 11, 2022 03:50
Unsound view types idea
#![feature(generic_associated_types)]
use std::{cell::UnsafeCell, marker::PhantomData};
////
// GAT-esque Deref and DerefMut
pub trait Deref<T> {
type Ref<'a>
where
@hlb8122
hlb8122 / tokens.rs
Last active March 8, 2022 11:47
Permission Tokens
#![allow(incomplete_features)]
#![feature(adt_const_params, specialization)]
use std::{
any::{Any, TypeId},
cell::UnsafeCell,
collections::HashMap,
marker::PhantomData,
};
@hlb8122
hlb8122 / limit.rs
Last active March 1, 2022 15:15
Wonky limit implementation
// TODO: Make this a named type/remove dyn
type SemaphoreFut = Pin<Box<dyn Future<Output = Result<OwnedSemaphorePermit, AcquireError>>>>;
#[pin_project(project_replace = StateReplaceProj, project = StateProj)]
enum State {
Pending(#[pin] SemaphoreFut),
Done(OwnedSemaphorePermit),
}
#[pin_project]
@hlb8122
hlb8122 / voyage.rs
Last active November 22, 2020 07:13
Compile Time Space Voyage
/// HMS-Oxide floats motionless, shimmering in a sunbeam, above...
pub struct Spacecraft;
/// ...the cool blue ocean planet.
pub struct OceanPlanet;
/// Every hospitable planet has to have a layer of Atmosphere...
pub struct Atmosphere<Altitude>(Altitude);
impl OceanPlanet {