Understanding Closures in Rust.

Andrew Pritchard
The Startup
Published in
6 min readJun 25, 2019

--

Summary

  • Closures are a combination of a function pointer (fn) and a context.
  • A closure with no context is just a function pointer.
  • A closure which has an immutable context belongs to Fn.
  • A closure which has a mutable context belongs to FnMut.
  • A closure that owns its context belongs to FnOnce.

Understanding the different types of closures in Rust.

--

--

Andrew Pritchard
The Startup

The stories I write are a part of a learning journey through life, logic and programming. Share this journey with me.