Accept borrowed values in InputWeightPrediction::new()

Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
This commit is contained in:
Harshil Jani 2023-02-25 17:20:40 +05:30
parent fbb3b82b93
commit f62885890d
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)
});