poulpy_hal/delegates/
scratch.rs

1use crate::{
2    api::{ScratchAvailable, ScratchFromBytes, ScratchOwnedAlloc, ScratchOwnedBorrow, TakeSlice},
3    layouts::{Backend, Scratch, ScratchOwned},
4    oep::{ScratchAvailableImpl, ScratchFromBytesImpl, ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeSliceImpl},
5};
6
7impl<B> ScratchOwnedAlloc<B> for ScratchOwned<B>
8where
9    B: Backend + ScratchOwnedAllocImpl<B>,
10{
11    fn alloc(size: usize) -> Self {
12        B::scratch_owned_alloc_impl(size)
13    }
14}
15
16impl<B> ScratchOwnedBorrow<B> for ScratchOwned<B>
17where
18    B: Backend + ScratchOwnedBorrowImpl<B>,
19{
20    fn borrow(&mut self) -> &mut Scratch<B> {
21        B::scratch_owned_borrow_impl(self)
22    }
23}
24
25impl<B> ScratchFromBytes<B> for Scratch<B>
26where
27    B: Backend + ScratchFromBytesImpl<B>,
28{
29    fn from_bytes(data: &mut [u8]) -> &mut Scratch<B> {
30        B::scratch_from_bytes_impl(data)
31    }
32}
33
34impl<B> ScratchAvailable for Scratch<B>
35where
36    B: Backend + ScratchAvailableImpl<B>,
37{
38    fn available(&self) -> usize {
39        B::scratch_available_impl(self)
40    }
41}
42
43impl<B> TakeSlice for Scratch<B>
44where
45    B: Backend + TakeSliceImpl<B>,
46{
47    fn take_slice<T>(&mut self, len: usize) -> (&mut [T], &mut Self) {
48        B::take_slice_impl(self, len)
49    }
50}