Skip to content

Instantly share code, notes, and snippets.

@ia0
ia0 / main.md
Last active March 17, 2024 16:08
Writing down my mental model of unsafe

Writing down my mental model of unsafe

DEPRECATION WARNING: This document is now deprecated. The new version is available here.

TLDR: All language constructs regarding unsafe Rust (including those that do not exist yet) can be explained by a single concept: the proof type (see first section). Understanding this concept is enough to understand unsafe.

I always assumed the content of this document to be obvious, but came to realize while discussing

@ia0
ia0 / flux.rs
Created January 24, 2025 21:20
Index-dependent refined vector
mod graph {
use flux_rs::*;
#[opaque]
#[refined_by(len: int)]
// Invariants (trusted):
// - There are len elements
// - The i-th element has type [Edge(i); 2]
pub struct Graph(Vec<[Edge; 2]>);