1 //! Traits for buffers providers with their own allocation policy. Users of this
2 //! interface leave the choice of which buffer to return to the implementor,
3 //! which must define its own allocation policy.
4 //!
5 //! The returned buffer shall not outlive the object that produced it.
6 
7 use thiserror::Error;
8 
9 use crate::memory::BufferHandles;
10 
11 use super::{CaptureQueueableProvider, OutputQueueableProvider};
12 
13 #[derive(Debug, Error)]
14 pub enum GetFreeBufferError {
15     #[error("all buffers are currently being used")]
16     NoFreeBuffer,
17 }
18 
19 pub trait GetFreeOutputBuffer<'a, P: BufferHandles, ErrorType = GetFreeBufferError>
20 where
21     Self: OutputQueueableProvider<'a, P>,
22 {
try_get_free_buffer(&'a self) -> Result<Self::Queueable, ErrorType>23     fn try_get_free_buffer(&'a self) -> Result<Self::Queueable, ErrorType>;
24 }
25 
26 pub trait GetFreeCaptureBuffer<'a, P: BufferHandles, ErrorType = GetFreeBufferError>
27 where
28     Self: CaptureQueueableProvider<'a, P>,
29 {
try_get_free_buffer(&'a self) -> Result<Self::Queueable, ErrorType>30     fn try_get_free_buffer(&'a self) -> Result<Self::Queueable, ErrorType>;
31 }
32