MENU

Fun & Interesting

Use the Rust Vec Type for Dynamically Expanding Arrays 🦀

Trevor Sullivan 4,754 2 years ago
Video Not Working? Fix It Now

In this video, we'll explore the Rust Vec type in the std::vec module. Vec is useful as a dynamically-sized array, and provides many helper methods for adding items, removing items, joining multiple Vec objects together, reserve additional system memory, and more! There's a vec! macro in Rust that simplifies instantiating a Vec. You can use the .push() method to add items to a mutable Vec. The .append() method on Vec allows you to join another Vec, with the same underlying data type, to itself. The .remove() method will delete an item from a Vec at a specific index. The .reserve() method can be used to reserve extra system memory if a Vec's size will be increased. You can also use .len() and .capacity() methods to monitor the number of items, and reserved size, for a given Vec. 🤯 Rust Programming Playlist 🦀 https://www.youtube.com/playlist?list=PLDbRgZ0OOEpUkWDGqp91ODn0dk7LPBAUL 📖 Rust Vec Type Reference: https://doc.rust-lang.org/std/vec/struct.Vec.html 📖 Using Rust Vec Type: https://doc.rust-lang.org/book/ch08-01-vectors.html Visual Studio Code ➡️ https://code.visualstudio.com Rust Website ➡️ https://rust-lang.org Rustup Installer ➡️ https://rustup.rs Rust Docs ➡️ https://doc.rust-lang.org/book Please follow me on these other social channels! ➡️ https://trevorsullivan.net ➡️ https://github.com/pcgeek86 ➡️ https://twitter.com/pcgeek86 ➡️ https://youtube.com/trevorsullivan ➡️ https://facebook.com/trevorsoftware ➡️ https://tiktok.com/pcgeek86 All trademarks, logos and brand names are the property of their respective owners. All company, product and service names used in this website are for identification purposes only. Use of these names,trademarks and brands does not imply endorsement. #rustlang #rust #rustdev #opensource #software #linux #devops #programming #rusty #dev #coding #codinglife #code #coder #ubuntu #ubuntulinux #appdev #developer

Comment