dope_sys/memory/buffer/
provided.rs1use crate::{
2 io::{Close, Retry},
3 memory,
4 memory::{buffer, buffer::canary},
5};
6
7pub trait Source {
9 const PROVIDED: u16;
10 const CANARY: u16;
11 type Index: buffer::Index;
12 type Context<L: memory::raw::Receive>: Context<Layout = L, Complete = Self::Complete<L::Extent>>;
13 type Canary<L: memory::raw::Canary>: canary::raw::Storage<
14 Layout = L,
15 Index = Self::Index,
16 State = <Self::Context<L> as Context>::Cleanup,
17 Error = <Self::Context<L> as Context>::Error,
18 >;
19 type Producer<L: memory::raw::Receive>: Producer<
20 Layout = L,
21 Context = Self::Context<L>,
22 Pending = Self::Pending<L::Extent>,
23 Index = Self::Index,
24 >;
25 type Pending<E: memory::raw::Extent>: buffer::raw::Token<Index = Self::Index, Length = E::Capacity>
26 + buffer::raw::Pending<Extent = E, Complete = Self::Complete<E>>;
27 type Complete<E: memory::raw::Extent>: buffer::raw::Token<Index = Self::Index, Length = E::Length>;
28}
29
30pub trait Context: Close + memory::Context + buffer::raw::Context<Self::Complete> {
32 type Error: Failure<Cleanup = Self::Cleanup>;
33 type Cleanup: Retry + memory::Failure;
34 type Complete: buffer::raw::Token;
35
36 fn new(layout: Self::Layout) -> Result<Self, Self::Error>;
37}
38
39pub trait Producer: Close + buffer::raw::Select + Sized {
41 type Layout: memory::raw::Receive;
42 type Context: Context;
43 type Error: Open<Context = Self::Context, Cleanup = <Self::Context as Context>::Cleanup>;
44
45 fn new(context: &Self::Context) -> Result<Self, Self::Error>;
46 fn flush(&mut self);
47 fn layout(&self) -> Self::Layout;
48}
49
50pub trait Failure {
52 type Cleanup: Retry + memory::Failure;
53
54 fn into_parts(self) -> (memory::Error, Option<Self::Cleanup>);
55}
56
57pub trait Open: Failure {
59 type Context: Context;
60
61 fn close(self, context: Self::Context) -> <Self::Context as Context>::Error;
62}