Something went wrong. Try again.
An experiment in static, refcounted, procedural language with ownership
Something went wrong. Try again.
868 B · 44 lines
Rust
at master
123456789101112131415161718192021222324252627282930313233343536373839404142434445#[derive(Debug, PartialOrd, Ord, Clone, Copy, Default)]pub struct Once<T>(Option<T>);
impl<T> Once<T> { pub fn new() -> Self { Self(None) }
#[inline] pub fn get(self) -> Option<T> { self.0 }
/// # Panics /// If the value is None #[inline] #[track_caller] pub fn unwrap(self) -> T { self.0.unwrap() }
/// # Panics /// If the value is already set #[inline] #[track_caller] pub fn set(&mut self, value: T) { assert!(self.0.is_none(), "already set"); self.0 = Some(value); }}
impl<T: PartialEq> PartialEq<T> for Once<T> { fn eq(&self, other: &T) -> bool { self.0.as_ref() == Some(other) }}
impl<T: PartialEq> PartialEq for Once<T> { fn eq(&self, other: &Self) -> bool { self.0 == other.0 }}
impl<T: Eq> Eq for Once<T> {}