Skip to content

Instantly share code, notes, and snippets.

@msullivan
msullivan / universal.rs
Last active February 3, 2020 19:18
Universal type in rust
// Safe implementation based on the existential power of closures.
mod ClosureUniversal {
// A value of universal type is a pair of functions. store will
// write the underlying value into the associated tag, while clear
// will erase the data in the tag to prevent space leaks.
pub struct Univ {
priv store: @fn(),
priv clear: @fn()
}