January 2019
Beginner to intermediate
554 pages
13h 31m
English
Type aliases are a feature not unique to Rust. C has the typedef keyword, while Kotlin has typealias for the same. They are there to make your code more readable and remove the type signature cruft that often piles up in statically typed languages, for example, if you have an API from your crate where you return a Result type, wrapping a complex object as depicted below:
// type_alias.rspub struct ParsedPayload<T> { inner: T}pub struct ParseError<E> { inner: E}pub fn parse_payload<T, E>(stream: &[u8]) -> Result<ParsedPayload<T>, ParseError<E>> { unimplemented!();}fn main() { // todo}
As you can see, for some of the methods, such as parse_payload, the type signature gets too large to fit in a line. Also, having to type Result<ParsedPayload<T>, ...
Read now
Unlock full access