Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "where for" mean in Rust?

Tags:

rust

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?

like image 581
Listerone Avatar asked Aug 25 '19 15:08

Listerone


People also ask

Does rust have higher Kinded types?

Rust does not have higher-kinded-types. For example, functor (and thus monad) cannot be written in Rust.

What is a monad 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.

Are rust enums monads?

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.


1 Answers

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.

like image 144
edwardw Avatar answered Nov 16 '22 03:11

edwardw