This SO answer uses a where
syntax I'm unfamiliar with:
fn readfile<'a, T: ?Sized>(filename: &str) -> Result<Box<Outer<'a, T>>, Box<std::error::Error>>
where
for<'de> T: Deserialize<'de> + 'a
{
...
What does the for
mean?
Where is this documented?
Rust does not have higher-kinded-types. For example, functor (and thus monad) cannot be written in Rust.
Monads are naturally structures at the level of type constructors, not types. Extending Rust to support full higher-kinded types raises many significant design questions. There are arguments that such an extension is simply infeasible.
In Rust, Monad would be a trait. However afaik Rust traits are not yet able to represent a monad. Option in Rust is roughly the same as Maybe in Haskell. In a way, Option is already a monad, it's just that Rust cannot (yet) generically abstract that functionality into a trait.
This is so-called higher-ranked trait bounds:
for<'a> can be read as "for all choices of 'a"
And it is defined by Rust RFC 0387.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With