To check the size of a Vector in Rust, you can use the len()
method of the Vec
struct. This returns the number of elements in the Vector.
main.rs91 chars4 lines
This will output:
main.rs18 chars2 lines
You can also use the capacity()
method to get the total amount of memory that has been allocated for the Vector:
main.rs108 chars4 lines
This will output:
main.rs22 chars2 lines
Note that the capacity()
method returns the number of elements that can be stored in the allocated space without requiring additional memory allocation.
gistlibby LogSnag