dope_sys/memory/buffer/raw.rs
1use o3::buffer;
2
3use crate::memory;
4
5type Extent<P> = <P as Pending>::Extent;
6type Rejection<P> = (
7 P,
8 <Extent<P> as memory::raw::Extent>::Length,
9 <Extent<P> as memory::raw::Extent>::Capacity,
10);
11
12/// A unique completion transfers one selected slot from its original ring.
13pub trait Select {
14 type Index: Copy;
15 type Pending: Token<Index = Self::Index>
16 + Pending<
17 Complete: Token<
18 Index = Self::Index,
19 Length = <Extent<Self::Pending> as memory::raw::Extent>::Length,
20 >,
21 >;
22
23 /// # Safety
24 /// A unique CQE transfers any valid reported slot from this ring.
25 /// Keep its payload live; project and return only through its original context/ring.
26 unsafe fn select(&self, index: Self::Index) -> Result<Self::Pending, Self::Index>;
27}
28
29/// # Safety
30/// The index names this owner's unique live slot and cannot change or duplicate.
31/// Its length denotes a live prefix wholly contained within that same slot.
32pub unsafe trait Token {
33 type Index: Copy;
34 type Length: Copy;
35
36 fn index(&self) -> Self::Index;
37 fn length(&self) -> Self::Length;
38}
39
40/// Returns a receive slot to its original native storage owner.
41pub trait Release<T> {
42 /// # Safety
43 /// The buffer is unique, has no live projections, and was issued by this owner.
44 /// Retain that storage until the return is consumed or published.
45 unsafe fn release(&mut self, buffer: T);
46}
47
48/// Projects a completed prefix from its original fixed-residency payload allocation.
49pub trait Context<T: Token>: buffer::raw::Fixed<T> {
50 /// # Safety
51 /// The completed token belongs to this exact context and retains its selected slot.
52 /// Its initialized prefix remains immutable and unavailable to the producer until the borrow ends.
53 unsafe fn bytes<'a>(&'a self, buffer: &'a T) -> &'a [u8];
54}
55
56/// A selected slot whose completed prefix has not yet been admitted.
57pub trait Pending: Sized {
58 type Extent: memory::raw::Extent;
59 type Complete;
60
61 fn try_complete(
62 self,
63 len: <Self::Extent as memory::raw::Extent>::Length,
64 ) -> Result<Self::Complete, Rejection<Self>>;
65}