# What are the for in types in Rust?

**URL:** <https://users.rust-lang.org/t/what-are-the-for-in-types-in-rust/2986>\
**Category:** help\
**Created:** [September 24, 2015, 2:03pm UTC](https://users.rust-lang.org/t/what-are-the-for-in-types-in-rust/2986 "2015-09-24T14:03:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![matklad](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/matklad/32/41370_2.png) [@matklad](https://users.rust-lang.org/u/matklad)\
**Post date:** [September 24, 2015, 2:03pm UTC](https://users.rust-lang.org/t/what-are-the-for-in-types-in-rust/2986/1 "2015-09-24T14:03:25Z")

</div>

Currently (1.3.0) rustc aссepts the following:

```rust
type T = for <'lt> fn (i32) -> i32;

```

What is this thing? 🙂 I failed to find anyting about it in the reference, so I guess that it is some obsolete syntax, but I'm not sure.

---

<div class="post-metadata">

**Author:** ![ogeon](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/ogeon/32/226_2.png) [@ogeon](https://users.rust-lang.org/u/ogeon)\
**Post date:** [September 24, 2015, 2:24pm UTC](https://users.rust-lang.org/t/what-are-the-for-in-types-in-rust/2986/2 "2015-09-24T14:24:33Z")

</div>

Not at all! It's actually very useful in some cases. It says "for any lifetime `'lt` ...", which is especially useful when using closures where you don't want to tie a lifetime to anything else: `<F: for<'a> Fn(A<'a>, B<'a>) -> C>`, compared to `<'a, F: Fn(A<'a>, B<'a>) -> C>`. An other case could be a where clause, like this:

```rust
impl<T> MyTrait for T where for<'a> &'a T: IntoIterator { ... }

```

This implements `MyTrait` for any type `T`, where a reference to it can be turned into an iterator. We don't care about the lifetime of the reference, so we will just specify it in that single predicate.

---

<div class="post-metadata">

**Author:** ![olivren](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/olivren/32/4827_2.png) [@olivren](https://users.rust-lang.org/u/olivren)\
**Post date:** [September 25, 2015, 9:08am UTC](https://users.rust-lang.org/t/what-are-the-for-in-types-in-rust/2986/3 "2015-09-25T09:08:08Z")

</div>

This is called a _higher ranked trait bound_. I discovered them after I asked [this question](https://users.rust-lang.org/t/trait-bounded-by-traits-and-lifetime-parameters/2327).

---

<div class="post-metadata">

**Author:** ![DenisKolodin](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/deniskolodin/32/1415_2.png) [@DenisKolodin](https://users.rust-lang.org/u/DenisKolodin)\
**Post date:** [September 25, 2015, 9:23am UTC](https://users.rust-lang.org/t/what-are-the-for-in-types-in-rust/2986/4 "2015-09-25T09:23:33Z")

</div>

Good description. I propose to write a separate book (after Rustonomicon) where we collect similar things.

I think **Rust Ruses Book** is a great name for that )

---

<div class="post-metadata">

**Author:** ![steffahn](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/steffahn/32/47569_2.png) [@steffahn](https://users.rust-lang.org/u/steffahn)\
**Post date:** [January 12, 2023, 8:37am UTC](https://users.rust-lang.org/t/what-are-the-for-in-types-in-rust/2986/5 "2023-01-12T08:37:52Z")

</div>


