use crate::{ghost::Plain, logic::ops::Fin, prelude::*};
use core::marker::PhantomData;
#[cfg(creusot)]
use core::ops::{Deref, DerefMut};
#[intrinsic("snapshot")]
pub struct Snapshot<T: ?Sized>(PhantomData<T>);
#[cfg(creusot)]
impl<T: ?Sized> Deref for Snapshot<T> {
type Target = T;
#[logic]
#[builtin("identity")]
#[intrinsic("snapshot_deref")]
fn deref(&self) -> &Self::Target {
dead
}
}
#[cfg(creusot)]
impl<T: ?Sized> DerefMut for Snapshot<T> {
#[logic]
#[builtin("identity")]
#[intrinsic("snapshot_deref_mut")]
fn deref_mut(&mut self) -> &mut Self::Target {
dead
}
}
impl<T: ?Sized + Fin> Fin for Snapshot<T> {
type Target = T::Target;
#[logic(open, prophetic, inline)]
fn fin<'a>(self) -> &'a Self::Target {
pearlite! { &^*self }
}
}
impl<T: ?Sized> Clone for Snapshot<T> {
#[check(ghost)]
#[ensures(result == *self)]
fn clone(&self) -> Self {
*self
}
}
impl<T: ?Sized> Copy for Snapshot<T> {}
impl<T: ?Sized> Snapshot<T> {
#[logic]
#[builtin("identity")]
pub fn new(value: T) -> Snapshot<T> {
let _ = value;
dead
}
}
impl<T> Snapshot<T> {
#[logic]
#[builtin("identity")]
pub fn inner(self) -> T {
dead
}
#[doc(hidden)]
#[cfg(not(creusot))]
pub fn from_fn(_: fn() -> T) -> Self {
Snapshot(PhantomData)
}
#[ensures(*result == *self)]
#[check(ghost)]
pub fn into_ghost(self) -> Ghost<T>
where
T: Plain,
{
T::into_ghost(self)
}
}