Unbox select traits (#547)
This commit is contained in:
parent
0077c9b6a5
commit
a2959712bb
|
@ -20,5 +20,5 @@ pub trait BlobCertificateSelect {
|
||||||
fn select_blob_from<'i, I: Iterator<Item = Self::Certificate> + 'i>(
|
fn select_blob_from<'i, I: Iterator<Item = Self::Certificate> + 'i>(
|
||||||
&self,
|
&self,
|
||||||
certificates: I,
|
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>(
|
fn select_blob_from<'i, I: Iterator<Item = Self::Certificate> + 'i>(
|
||||||
&self,
|
&self,
|
||||||
certificates: I,
|
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>(
|
utils::select::select_from_till_fill_size::<SIZE, Self::Certificate>(
|
||||||
|blob| blob.as_bytes().len(),
|
|blob| blob.as_bytes().len(),
|
||||||
certificates,
|
certificates,
|
||||||
|
|
|
@ -28,5 +28,5 @@ pub trait TxSelect {
|
||||||
fn select_tx_from<'i, I: Iterator<Item = Self::Tx> + 'i>(
|
fn select_tx_from<'i, I: Iterator<Item = Self::Tx> + 'i>(
|
||||||
&self,
|
&self,
|
||||||
txs: I,
|
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>(
|
fn select_tx_from<'i, I: Iterator<Item = Self::Tx> + 'i>(
|
||||||
&self,
|
&self,
|
||||||
txs: I,
|
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)
|
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>(
|
pub fn select_from_till_fill_size<'i, const SIZE: usize, T>(
|
||||||
mut measure: impl FnMut(&T) -> usize + 'i,
|
mut measure: impl FnMut(&T) -> usize + 'i,
|
||||||
items: impl Iterator<Item = T> + 'i,
|
items: impl Iterator<Item = T> + 'i,
|
||||||
) -> Box<dyn Iterator<Item = T> + 'i> {
|
) -> impl Iterator<Item = T> + 'i {
|
||||||
let mut current_size = 0usize;
|
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 += measure(item);
|
||||||
current_size <= SIZE
|
current_size <= SIZE
|
||||||
}))
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue