use o3::base::num::bounded;
use crate::{
memory,
probe::{Cause, Outcome, Stopped, cleanup::Rejection},
ring,
ring::register::Occupied,
};
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Outside {
Abi(bounded::U32<0, { i32::MAX as u32 }>),
Capacity {
actual: bounded::U32<0, { (1 << 24) - 1 }>,
limit: bounded::U32<0, { (1 << 24) - 1 }>,
},
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Check<P> {
Early(P),
Outside { probe: P, cause: Outside },
}
pub trait Validate<L: memory::raw::Canary, P: Copy, R: Copy>: Sized {
type Range: Range;
type Probe: Copy;
type Update;
type Cleanup;
type Release;
fn accept(
self,
range: Self::Range,
release: impl FnOnce(Self::Probe, Self::Update) -> R,
) -> Result<Self, Rejection<Self::Cleanup, Self::Release>>;
}
pub trait Range {
type Target;
type Value;
fn fixed(&self) -> Self::Target;
fn accepted(&self, observed: Self::Value) -> Result<Self::Target, Outside>;
}
type Fault<A> = Cause<
<A as Accept>::Probe,
<<A as Accept>::Outcome as Outcome>::Observation,
<A as Accept>::Error,
>;
pub trait Accept: Sized {
type Ring: ring::Owner<File = Self::File, Closing = Self::Closing>;
type Owned;
type Probe: Copy;
type Outcome: Outcome<Probe = Self::Probe>;
type Error;
type File: Occupied;
type Closing;
fn new(ring: Self::Ring, probe: Self::Probe) -> Self;
fn submit(
self,
entry: Self::Owned,
) -> Result<(Self, Self::Outcome), Stopped<Self, Fault<Self>>>;
fn cancel(self) -> Result<Self::Ring, Stopped<Self, Fault<Self>>>;
fn try_close(self, file: Self::File) -> Result<(), Self::Closing>;
}