Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn main() {
- // Declare an empty vector
- let mut vec = Vec::new();
- // Append data to the tail of the vector
- vec.push(1);
- vec.push(2);
- vec.push(3);
- // Get the length of the vector
- assert_eq!(vec.len(), 3);
- // Pop data from the tail of the vector
- let popped = vec.pop().unwrap();
- assert_eq!(popped, 3);
- assert_eq!(vec, vec![1, 2]);
- // Insert data into the middle of the vector
- vec.insert(1, 99);
- assert_eq!(vec, vec![1, 99, 2]);
- // Remove data from the middle of the vector
- let removed = vec.remove(1);
- assert_eq!(removed, 99);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement