1use o3::base::num::bounded;
2
3use crate::{
4 memory,
5 probe::{Cause, Outcome, Stopped, cleanup::Rejection},
6 ring,
7 ring::register::Occupied,
8};
9
10#[derive(Clone, Copy, Debug, Eq, PartialEq)]
12pub enum Outside {
13 Abi(bounded::U32<0, { i32::MAX as u32 }>),
14 Capacity {
15 actual: bounded::U32<0, { (1 << 24) - 1 }>,
16 limit: bounded::U32<0, { (1 << 24) - 1 }>,
17 },
18}
19
20#[derive(Clone, Copy, Debug, Eq, PartialEq)]
22pub enum Check<P> {
23 Early(P),
24 Outside { probe: P, cause: Outside },
25}
26
27pub trait Validate<L: memory::raw::Canary, P: Copy, R: Copy>: Sized {
29 type Range: Range;
30 type Probe: Copy;
31 type Update;
32 type Cleanup;
33 type Release;
34
35 fn accept(
36 self,
37 range: Self::Range,
38 release: impl FnOnce(Self::Probe, Self::Update) -> R,
39 ) -> Result<Self, Rejection<Self::Cleanup, Self::Release>>;
40}
41
42pub trait Range {
44 type Target;
45 type Value;
46
47 fn fixed(&self) -> Self::Target;
48 fn accepted(&self, observed: Self::Value) -> Result<Self::Target, Outside>;
49}
50
51type Fault<A> = Cause<
52 <A as Accept>::Probe,
53 <<A as Accept>::Outcome as Outcome>::Observation,
54 <A as Accept>::Error,
55>;
56
57pub trait Accept: Sized {
59 type Ring: ring::Owner<File = Self::File, Closing = Self::Closing>;
60 type Owned;
61 type Probe: Copy;
62 type Outcome: Outcome<Probe = Self::Probe>;
63 type Error;
64 type File: Occupied;
65 type Closing;
66
67 fn new(ring: Self::Ring, probe: Self::Probe) -> Self;
68 fn submit(
69 self,
70 entry: Self::Owned,
71 ) -> Result<(Self, Self::Outcome), Stopped<Self, Fault<Self>>>;
72 fn cancel(self) -> Result<Self::Ring, Stopped<Self, Fault<Self>>>;
73 fn try_close(self, file: Self::File) -> Result<(), Self::Closing>;
74}