vitaminc_async_traits/
lib.rs1#![doc = include_str!("../README.md")]
2use vitaminc_protected::Zeroed;
3use vitaminc_traits::OutputSize;
4
5#[allow(async_fn_in_trait)]
9pub trait AsyncFixedOutput<const N: usize, O>: Sized
10where
11 O: Sized + Send + OutputSize<N>,
13{
14 type Error;
15
16 async fn try_finalize_into(self, out: &mut O) -> Result<(), Self::Error>;
18
19 #[inline]
21 async fn try_finalize_fixed(self) -> Result<O, Self::Error>
22 where
23 O: Zeroed,
24 {
25 let mut out = Zeroed::zeroed();
26 if let Err(err) = self.try_finalize_into(&mut out).await {
27 Err(err)
28 } else {
29 Ok(out)
30 }
31 }
32}
33
34#[allow(async_fn_in_trait)]
38pub trait AsyncFixedOutputReset<const N: usize, O>
39where
40 O: OutputSize<N>,
41{
42 type Error;
43
44 async fn try_finalize_into_reset(&mut self, out: &mut O) -> Result<(), Self::Error>;
45
46 #[inline]
47 async fn try_finalize_fixed_reset(&mut self) -> Result<O, Self::Error>
48 where
49 O: Zeroed,
50 {
51 let mut out = Zeroed::zeroed();
52 if let Err(err) = self.try_finalize_into_reset(&mut out).await {
53 Err(err)
54 } else {
55 Ok(out)
56 }
57 }
58}