October 2018
Beginner
180 pages
4h 48m
English
The Rust compiler automatically implements Any for any data type, unless that data type contains non-static references. So, our Forward, Turn, and Stop structures that we used in the trait objects section already automatically implement Any, but something like this would not:
pub struct DoesNotHaveAnyTrait<'a> { pub name: &'a str, pub count: i32,}
More accurately, DoesNotHaveAnyTrait only has the Any trait when 'a is equal to 'static, which it is if we use a simple string expression such as this is a static string to initialize it, but not if we use some other mechanism for retrieving or constructing an &str value.
The error the compiler will give if we try something impossible along these lines will probably ...
Read now
Unlock full access