I have the following code:
pub enum Lazy<T, F: Fn() -> T> {
Uninitialized(F),
Initialized(T),
}
impl<T, F: Fn() -> T> Lazy<T, F> {
pub fn new(init: F) -> Lazy<T, F> {
Lazy::Uninitialized(init)
}
}
impl<T: Default> Lazy<T, _> {
pub fn new_default() -> Lazy<T, _> {
Lazy::Uninitialized(T::default)
}
}
The second impl
block is obviously invalid as is (with underscores for type parameters). What I'm trying to do is figure out how to write down the type of <T as Default>::default
, which should implement Fn() -> T
, and put that type where the underscores are now, but I can't figure out how to write down its type explicitly.