diff --git a/module/core/iter_tools/examples/iter_tools_trivial.rs b/module/core/iter_tools/examples/iter_tools_trivial.rs index 2dfe3b101b..01ed1630e7 100644 --- a/module/core/iter_tools/examples/iter_tools_trivial.rs +++ b/module/core/iter_tools/examples/iter_tools_trivial.rs @@ -1,27 +1,35 @@ -//! qqq : write proper description - +//! This example demonstrates the usage of some standard and non-standard functions +//! from the `iter_tools` crate. The `iter_tools` crate provides additional iterator +//! methods beyond those provided by the standard library. #[ cfg( not( feature = "enabled" ) ) ] fn main() {} #[ cfg( feature = "enabled" ) ] fn main() { + // Importing functions from the `iter_tools` crate use iter_tools::*; /* standard functions */ + // Creating a vector let vec = vec![ 5, 1, -2 ]; + // Finding the minimum value in the vector let min = min( &vec ); assert_eq!( *min.unwrap(), -2 ); /* non standard functions */ + // Creating another vector let vec = vec![ 5, 1, -2 ]; - let added = vec![ "a", "b", "c" ]; + // Initializing an empty vector to store the result let mut result = vec![]; - let zipped = zip( &vec, &added ); - for( left, right ) in zipped + // Reversing the vector using the `rev` function from `iter_tools` + let reversed = rev( &vec ); + // Iterating over the reversed vector + for v in reversed { - result.push( ( *left, *right ) ); + // Pushing the dereferenced value into the result vector + result.push( *v ); } - assert_eq!( result, vec![ ( 5, "a" ), ( 1, "b" ), ( -2, "c" ) ] ); + assert_eq!( result, vec![ -2, 1, 5, ] ); }