Skip to content

Commit 7301772

Browse files
committed
Add BufKind GAT to Buffer trait
1 parent 94d1fd6 commit 7301772

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

cryprot-core/src/buf.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ use crate::alloc::{HugePageMemory, allocate_zeroed_vec};
1414
pub trait Buf<T>:
1515
Default + Debug + Deref<Target = [T]> + DerefMut + Send + Sync + 'static + private::Sealed
1616
{
17+
/// The 'kind' of this Buf implementation. This is e.g. `Vec<E>` for `Vec<T>
18+
/// as Buf<T>`.
19+
///
20+
/// This associated type can be used to create Bufs of the same kind, but
21+
/// with a different inner type.
22+
type BufKind<E>: Buf<E>
23+
where
24+
E: Zeroable + Clone + Default + Debug + Send + Sync + 'static;
1725
/// Create a new `Buf` of length `len` with all elements set to zero.
1826
///
1927
/// Implementations of this directly allocate zeroed memory and do not write
@@ -41,6 +49,11 @@ pub trait Buf<T>:
4149
}
4250

4351
impl<T: Zeroable + Clone + Default + Debug + Send + Sync + 'static> Buf<T> for Vec<T> {
52+
type BufKind<E>
53+
= Vec<E>
54+
where
55+
E: Zeroable + Clone + Default + Debug + Send + Sync + 'static;
56+
4457
fn zeroed(len: usize) -> Self {
4558
allocate_zeroed_vec(len)
4659
}
@@ -66,6 +79,11 @@ impl<T: Zeroable + Clone + Default + Debug + Send + Sync + 'static> Buf<T> for V
6679
}
6780

6881
impl<T: Zeroable + Clone + Default + Debug + Send + Sync + 'static> Buf<T> for HugePageMemory<T> {
82+
type BufKind<E>
83+
= HugePageMemory<E>
84+
where
85+
E: Zeroable + Clone + Default + Debug + Send + Sync + 'static;
86+
6987
fn zeroed(len: usize) -> Self {
7088
HugePageMemory::zeroed(len)
7189
}

0 commit comments

Comments
 (0)