October 2018
Beginner
180 pages
4h 48m
English
So, instead of an array of enumeration values, this time we're going to create an array of trait object references:
let mut directions = [ &Forward{ blocks: 5 }, &Turn{ slight: true, right: false }, &Forward{ blocks: 1 }, &Turn{ slight: false, right: true }, &Forward{ blocks: 2 }, &Stop{}, ];
Unfortunately, if we try to compile that, we get an error, as shown here:

This time, Rust can't figure out the data type of the array just by looking at the value we're assigning to it, because that value looks like an array containing multiple data types, which is not something we can even do in Rust. The compiler ...
Read now
Unlock full access