Unbox select traits
This commit is contained in:
parent
0077c9b6a5
commit
7ef5dce8e1
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}))
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue