The code example is Rust written as if it were classic C. In Rust, that example would usually be written like this:
/// Find leading zeros in an array of bytes.
fn find_leading_0s(bytes: &mut [u8]) -> Option<&mut [u8]> {
if let Some(pos) = bytes.iter().position(|v| *v != 0 ) { // search
Some(&mut bytes[..pos]) // find
} else {
None // no find
}
}
Rust isn't a fully functional language, but the functional features play well with the lifetime system and are optimized well.(Rust playground example: https://play.rust-lang.org/?version=stable&mode=debug&editio...)