October 2019
Intermediate to advanced
444 pages
10h 37m
English
Lifetimes can be explored in a few steps:
// declaring a lifetime is optional here, since the compiler automates this////// Compute the arithmetic mean/// pub fn mean<'a>(numbers: &'a [f32]) -> Option<f32> { if numbers.len() > 0 { let sum: f32 = numbers.iter().sum(); Some(sum / numbers.len() as f32) } else { None }}