March 2018
Intermediate to advanced
272 pages
7h 4m
English
Let's start with a simple example. This Rust code will perform poorly:
let arr = ['a', 'b', 'c', 'd', 'e', 'f']; for i in 0..arr.len() { println!("{}", arr[i]); }
This will, of course, work, and it's perfectly safe. We create an index that goes from 0 to the length of the array (6 in this case), but exclude the last one, so the i binding will take the values 0, 1, 2, 3, 4, and 5. For each of them, it will get the element at that index in the array and print it in a new line. There is one problem with this approach though. In C/C++, an equivalent code will simply add the size of the element to the pointer in the array and get the next element, but that sometimes causes issues. Look at this code:
let arr = ['a', 'b', ...
Read now
Unlock full access