Earlier this week, Jon dropped his screencast on "Crust of Rust: functions, closures, and their traits". When he covered
dyn Fn
towards the end of his talk, he noticed this had not been implemented on Arc
.I was curious and reached out to him over Twitter and set about looking into extending this, and did this intentionally so as to get my feet wet within the inner workings of Rust.
Just by going through this process, I was able to setup my local dev environment to compile the bootstrapped Rust compiler as "Stage 1", and I was off to the races.
First, I wanted to try and solve the missing implementation, and I naively setup the
Fn
trait hierarchy wrong. Even experts in the Rust Discord channel were initially baffled, until one chap had a great idea, which helped a lot. I ran with it, and ended up pushing this PR.However, this solution has been tried before and is a "breaking" change, but there are those out there who would still like to have this available, to do something like this
use std::sync::Arc;
trait GenFn {
type Output: Fn() -> String;
fn gen(&mut self) -> Self::Output;
}
struct FnBuilder;
impl GenFn for FnBuilder {
type Output = Arc<dyn Fn() -> String>;
fn gen(&mut self) -> Self::Output {
Arc::new(|| "Hello World!".to_string())
}
}
For now, the PR is still open. Let's see what happens.
It's also a great idea just to fork and keep the source on your laptop for example, as you can generate all the important docs with `./x.py doc`. This gives you the entire Rust documentation fully accessible without the need for an internet connection. How awesome is that?