trait
Product — result type for iterator products
Define the output of multiplying a sequence of items. For primitive integers the empty product is one, not zero; arithmetic may overflow for large inputs. Expected stdout (not executed): 24 Common mistake: Expecting a multiplication trait implementation to provide Product automatically.
Formal Syntax & Structure
rust syntaxrust
pub trait Product<A = Self>: Sized { fn product<I>(iter: I) -> Self where I: Iterator<Item = A>; }Working Example
Example Snippetrust
fn main() { use std::iter::Product; fn multiply<T: Product<u32>>(values: impl Iterator<Item = u32>) -> T { values.product() } let value: u32 = multiply([2, 3, 4].into_iter()); println!("{value}");}