From 8903f4cafe9ebcf6ad6459f403c495c5aacdbf4b Mon Sep 17 00:00:00 2001 From: Manichand Kondapaka Date: Tue, 6 Feb 2024 16:22:10 +0530 Subject: [PATCH] Added a different way of vector intialization. Specifying ```Vec::::new()``` explicitly indicates that variable is intended to be a vector containing String elements. This can be helpful for documenting the code and ensuring that variable is used correctly throughout the codebase. --- src/std-types/vec.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/std-types/vec.md b/src/std-types/vec.md index 6684a6608ea6..fc6a741920ac 100644 --- a/src/std-types/vec.md +++ b/src/std-types/vec.md @@ -20,6 +20,9 @@ fn main() { // Canonical macro to initialize a vector with elements. let mut v3 = vec![0, 0, 1, 2, 3, 4]; + // specifying the type when initializing a vector. + let mut v4 = Vec::::new(); + // Retain only the even elements. v3.retain(|x| x % 2 == 0); println!("{v3:?}");