Unbox select traits

This commit is contained in:
danielsanchezq 2024-01-02 10:27:22 +01:00
parent 0077c9b6a5
commit 7ef5dce8e1
5 changed files with 7 additions and 7 deletions

View File

@ -20,5 +20,5 @@ pub trait BlobCertificateSelect {
fn select_blob_from<'i, I: Iterator<Item = Self::Certificate> + 'i>(
&self,
certificates: I,
) -> Box<dyn Iterator<Item = Self::Certificate> + 'i>;
) -> impl Iterator<Item = Self::Certificate> + 'i;
}

View File

@ -30,7 +30,7 @@ impl<const SIZE: usize, C: Certificate> BlobCertificateSelect for FillSize<SIZE,
fn select_blob_from<'i, I: Iterator<Item = Self::Certificate> + 'i>(
&self,
certificates: I,
) -> Box<dyn Iterator<Item = Self::Certificate> + 'i> {
) -> impl Iterator<Item = Self::Certificate> + 'i {
utils::select::select_from_till_fill_size::<SIZE, Self::Certificate>(
|blob| blob.as_bytes().len(),
certificates,

View File

@ -28,5 +28,5 @@ pub trait TxSelect {
fn select_tx_from<'i, I: Iterator<Item = Self::Tx> + 'i>(
&self,
txs: I,
) -> Box<dyn Iterator<Item = Self::Tx> + 'i>;
) -> impl Iterator<Item = Self::Tx> + 'i;
}

View File

@ -30,7 +30,7 @@ impl<const SIZE: usize, Tx: Transaction> TxSelect for FillSize<SIZE, Tx> {
fn select_tx_from<'i, I: Iterator<Item = Self::Tx> + 'i>(
&self,
txs: I,
) -> Box<dyn Iterator<Item = Self::Tx> + 'i> {
) -> impl Iterator<Item = Self::Tx> + 'i {
utils::select::select_from_till_fill_size::<SIZE, Self::Tx>(|tx| tx.as_bytes().len(), txs)
}
}

View File

@ -1,10 +1,10 @@
pub fn select_from_till_fill_size<'i, const SIZE: usize, T>(
mut measure: impl FnMut(&T) -> usize + 'i,
items: impl Iterator<Item = T> + 'i,
) -> Box<dyn Iterator<Item = T> + 'i> {
) -> impl Iterator<Item = T> + 'i {
let mut current_size = 0usize;
Box::new(items.take_while(move |item: &T| {
items.take_while(move |item: &T| {
current_size += measure(item);
current_size <= SIZE
}))
})
}