Merge rust-bitcoin/rust-bitcoin#1672: Accept borrowed values in InputWeightPrediction::new()

f62885890d Accept borrowed values in InputWeightPrediction::new() (Harshil Jani)

Pull request description:

  The updated implementation accepts borrowed values and now it is convenient to use with slices.

  closes #1669

ACKs for top commit:
  Kixunil:
    ACK f62885890d
  apoelstra:
    ACK f62885890d

Tree-SHA512: 59459e640a9676f3c293b10227026635b06fe55d31ffd2da606c0c70aac614694f48ba2f43bb3e8dce047e35e007fb2b09528d7dcfd0772e6b678680e2d781ea
This commit is contained in:
Andrew Poelstra 2023-02-25 14:33:44 +00:00
commit 277eef486a
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
1 changed files with 3 additions and 2 deletions

View File

@ -1278,11 +1278,12 @@ pub struct InputWeightPrediction {
impl InputWeightPrediction {
/// Computes the prediction for a single input.
pub fn new<I>(input_script_len: usize, witness_element_lengths: I) -> Self
where I: IntoIterator<Item = usize>,
pub fn new<T>(input_script_len: usize, witness_element_lengths: T) -> Self
where T :IntoIterator, T::Item:Borrow<usize>,
{
let (count, total_size) = witness_element_lengths.into_iter()
.fold((0, 0), |(count, total_size), elem_len| {
let elem_len = *elem_len.borrow();
let elem_size = elem_len + VarInt(elem_len as u64).len();
(count + 1, total_size + elem_size)
});