I'm ramping up on Rust from a Java/C background. Pretty happy so far. One thing that keeps getting in my way is the implicit type signatures on variables. I know the compiler knows the type of each variable, but it will often help improve my understanding if I also know :)
I'm currently uses CLion with the Rust plugin. It does a decent job with Rust, but the "extract expression to variable" action, which I frequently use to remind myself of the type of an expression, uses implicit type signatures for Rust.
For example, I am really curious what the type signature is for a vector of Futures, because the Future trait has a type parameter and I've never seen one written out before. The Book didn't have any ready examples for me either, unfortunately.
let requests = endpoints.iter()
.map(|endpoint| client.get(format!("..{}..",..endpoint..)).send())
.collect();
I know this is a vector of futures that will yield a Result containing either a Response or an Error. I just don't know how to express that yet.
let requests : Vec<Future<Output=Result<Response,reqwest::Error>>> = ...
error[E0277]: the size for values of type `dyn std::future::Future<Output = std::result::Result<reqwest::async_impl::response::Response, reqwest::error::Error>>` cannot be known at compilation time
let requests : Vec<impl Future<Output=Result<Response,reqwest::Error>>> = ...
error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
let requests : Vec<Future<Result<Response,reqwest::Error>>> = ...
error[E0107]: wrong number of type arguments: expected 0, found 1
let requests : Vec<impl Future<Result<Response, reqwest::Error>>> = ...
error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
let requests : Vec<Box<dyn Future<Output = Result<Response, reqwest::Error>>>> = ...
.map(Box::new)
.collect()
error[E0277]: a collection of type `std::vec::Vec<std::boxed::Box<dyn std::future::Future<Output = std::result::Result<reqwest::async_impl::response::Response, reqwest::error::Error>>>>` cannot be built from an iterator over elements of type `std::boxed::Box<impl std::future::Future>`