Skip to main content

dope_sys/memory/buffer/
provided.rs

1use std::{num, ptr};
2
3use crate::{
4    io::{Close, Retry},
5    memory,
6    memory::{buffer, buffer::canary},
7};
8
9/// Selects native pending and completed provided-buffer ownership.
10pub trait Source {
11    const PROVIDED: u16;
12    const CANARY: u16;
13    type Index: buffer::Index;
14    type Context<L: memory::raw::Receive>: Context<Layout = L, Complete = Self::Complete<L::Extent>, Cleanup = Self::Cleanup<L>>;
15    type Canary<L: memory::raw::Canary>: canary::raw::Storage<
16            Layout = L,
17            Index = Self::Index,
18            State = Self::Cleanup<L>,
19            Error = <Self::Context<L> as Context>::Error,
20        >;
21    type Cleanup<L: memory::raw::Receive>: Cleanup<Context = Self::Context<L>, Producer = Self::Producer<L>>;
22    type Producer<L: memory::raw::Receive>: Producer<
23            Layout = L,
24            Context = Self::Context<L>,
25            Pending = Self::Pending<L::Extent>,
26            Index = Self::Index,
27        >;
28    type Pending<E: memory::raw::Extent>: buffer::raw::Token<Index = Self::Index, Length = E::Capacity>
29        + buffer::raw::Pending<Extent = E, Complete = Self::Complete<E>>;
30    type Complete<E: memory::raw::Extent>: buffer::raw::Token<Index = Self::Index, Length = E::Length>;
31}
32
33/// Payload ownership and exact completed-prefix projection for one receive ring.
34pub trait Context: Close + memory::Context + buffer::raw::Context<Self::Complete> {
35    type Error: Failure<Cleanup = Self::Cleanup>;
36    type Cleanup: Retry + memory::Failure;
37    type Complete: buffer::raw::Token;
38
39    fn new(layout: Self::Layout) -> Result<Self, Self::Error>;
40    fn as_ptr(&self) -> *const u8;
41}
42
43/// Native ring entries and deferred publication, paired with one payload owner.
44pub trait Producer: Close + buffer::raw::Select + Sized {
45    type Layout: memory::raw::Receive;
46    type Context: Context;
47    type Entry: Copy;
48    type Error: Open<Context = Self::Context, Cleanup = <Self::Context as Context>::Cleanup>;
49
50    fn new(context: &Self::Context) -> Result<Self, Self::Error>;
51    fn flush(&mut self);
52    fn layout(&self) -> Self::Layout;
53    fn registration(&self) -> (ptr::NonNull<Self::Entry>, num::NonZero<u16>);
54}
55
56/// The original mapping failure and any storage still requiring cleanup.
57pub trait Failure {
58    type Cleanup: Retry + memory::Failure;
59
60    fn into_parts(self) -> (memory::Error, Option<Self::Cleanup>);
61}
62
63/// A failed producer allocation that can retire its paired payload owner.
64pub trait Open: Failure {
65    type Context: Context;
66
67    fn close(self, context: Self::Context) -> <Self::Context as Context>::Error;
68}
69
70/// Exact native storage states retained until all mappings are released.
71pub trait Cleanup: Retry + memory::Failure {
72    type Context: Context;
73    type Producer: Producer<Context = Self::Context>;
74
75    fn payload(current: <Self::Context as Close>::State) -> Self;
76    fn producer(current: <Self::Producer as Close>::State) -> Self;
77}