I'm reading the book "Programming Rust, 2nd Edition" by Jim Blandy, Jason Orendorff, Leonora F. S. Tindall. It says that 'static is the default for impl return types.
This version lets the async block capture host and path as owned String values, not &str references. Since the future owns all the data it needs to run, it is valid for the 'static lifetime. (We’ve spelled out + 'static in the signature shown earlier, but 'static is the default for -> impl return types, so omitting it would have no effect.)
fn cheapo_request<'a>(
host: &'a str,
port: u16,
path: &'a str,
) -> impl Future<Output = io::Result<String>> + 'static {
let host = host.to_string();
let path = path.to_string();
async move { ... use &*host, port, and path ... }
}
To my understanding, the return future may or may not contain references. Its lifetime may not be 'static.
- Why is
'staticthe default forimplreturn types? - Further question, is any type without explicit lifetime annotation assumed to be
'static?