---
source: https://iinventedlight.com/library/notes/rust-closures.md
title: "Rust closures: capturing the environment and the Fn traits"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT or Apache-2.0 (rust-lang/book; Copyright (c) 2010 The Rust Project Developers; https://github.com/rust-lang/book/blob/main/LICENSE-MIT); MIT or Apache-2.0 (rust-lang/rust-by-example; Copyright (c) 2014 Jorge Aparicio; https://github.com/rust-lang/rust-by-example/blob/master/LICENSE-MIT); prose restates or closely paraphrases cited source lines"
license_family: rust-mit
rule_check: "needs rule check (family not in auto-publish rule; check.mjs auto-approves only usgov and arxiv-ccby)"
attribution: "Summary by iinventedlight (AI-assisted). Sources: The Rust Programming Language, Closures - The Rust Programming Language, MIT or Apache-2.0 (rust-lang/book; Copyright (c) 2010 The Rust Project Developers; https://github.com/rust-lang/book/blob/main/LICENSE-MIT); Rust by Example, Closures - Rust By Example, MIT or Apache-2.0 (rust-lang/rust-by-example; Copyright (c) 2014 Jorge Aparicio; https://github.com/rust-lang/rust-by-example/blob/master/LICENSE-MIT)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-04
status: published
checked_on: 2026-11-04
as_of: 2026-11-04
confidence: medium
untested: "No code was run for this note; only the fetched documentation pages were read."
category: coding-references
topic_area: "code-ai-eng: Rust"
tags: ['rust', 'closures', 'fn-traits']
sources:
  - id: S1
    title: "Closures - The Rust Programming Language"
    publisher: The Rust Programming Language
    url: https://doc.rust-lang.org/book/ch13-01-closures.html
    accessed: 2026-11-04
    license: "MIT or Apache-2.0 (rust-lang/book; Copyright (c) 2010 The Rust Project Developers; https://github.com/rust-lang/book/blob/main/LICENSE-MIT)"
  - id: S2
    title: "Closures - Rust By Example"
    publisher: Rust by Example
    url: https://doc.rust-lang.org/rust-by-example/fn/closures.html
    accessed: 2026-11-04
    license: "MIT or Apache-2.0 (rust-lang/rust-by-example; Copyright (c) 2014 Jorge Aparicio; https://github.com/rust-lang/rust-by-example/blob/master/LICENSE-MIT)"
---
# Rust closures: capturing the environment and the Fn traits

**Answer:** Rust's closures are anonymous functions you can save in a variable or pass as arguments to other functions. Unlike functions, closures can capture values from the scope in which they're defined. (S1)

## Syntax

- Closures don't usually require you to annotate the types of the parameters or the return value like fn functions do. (S1)
- Calling a closure is exactly like calling a function. (S2)
- Once a closure's type has been inferred, it cannot be inferred again with another type. (S2)

## Capturing

- Closures can capture values from their environment in three ways: borrowing immutably, borrowing mutably, and taking ownership. (S1)
- If you want to force the closure to take ownership of the values it uses in the environment, you can use the move keyword before the parameter list. (S1)

## The Fn traits

- The way a closure captures and handles values from the environment affects which traits the closure implements. (S1)
- FnOnce applies to closures that can be called once, and all closures implement at least this trait because all closures can be called. (S1)
- A closure that moves captured values out of its body will only implement FnOnce and none of the other Fn traits. (S1)
- FnMut applies to closures that don't move captured values out of their body but might mutate the captured values. (S1)
- If what we want to do doesn't require capturing a value from the environment, we can use the name of a function rather than a closure. (S1)

## Claims
- id: C1
  claim: Closures can capture values from their defining scope.
  source: S1
  evidence: "closures can capture values from the scope in which they’re defined."
- id: C2
  claim: move forces a closure to take ownership.
  source: S1
  evidence: "you can use the move keyword before the parameter list."
- id: C3
  claim: All closures implement FnOnce.
  source: S1
  evidence: "at least this trait because all closures can be called."
- id: C4
  claim: Closures capture the enclosing environment.
  source: S2
  evidence: "Closures are functions that can capture the enclosing environment."

## Sources
- [S1] Closures - The Rust Programming Language. The Rust Programming Language. https://doc.rust-lang.org/book/ch13-01-closures.html . License: MIT or Apache-2.0 (rust-lang/book; Copyright (c) 2010 The Rust Project Developers; https://github.com/rust-lang/book/blob/main/LICENSE-MIT). Accessed 2026-11-04.
- [S2] Closures - Rust By Example. Rust by Example. https://doc.rust-lang.org/rust-by-example/fn/closures.html . License: MIT or Apache-2.0 (rust-lang/rust-by-example; Copyright (c) 2014 Jorge Aparicio; https://github.com/rust-lang/rust-by-example/blob/master/LICENSE-MIT). Accessed 2026-11-04.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).
