Skip to content

Instantly share code, notes, and snippets.

View dklassen's full-sized avatar

Dana Klassen dklassen

View GitHub Profile
@dklassen
dklassen / phantom_type_state_encoding.rs
Last active January 19, 2025 15:15
Had a problem defining constraints to represent Sqlite Column constraints. Started to fool around with PhantomData and was curious to see if I could achieve what I wanted roughly with typing. This is what the end result was: using Phantom Data to encode stateful logic around adding and transitioning constraints.
use std::collections::HashSet as Set;
use std::marker::PhantomData;
// Marker traits for states
pub trait KeyState {}
pub struct InvalidState;
impl KeyState for InvalidState {}
pub trait UsableState {}