Get the latest tech news

The rules behing Rust functions


Demystifying fn, Fn, FnMut, and FnOnce from everyday usage to compiler magic under the hood

When you write a closure, the Rust compiler internally transforms it into a compiler-generated anonymous struct with trait implementations: Since there's no captured state to store, Rust can coerce such closures directly to plain function pointers: Feel free to reach out on X, LinkedIn, or subscribe to my blog ( substack, medium) to keep pushing the boundaries together!

Get the Android app

Or read this on Hacker News

Read more on:

Photo of Rules

Rules

Photo of Rust functions

Rust functions

Related news:

News photo

Ted Cruz’s new bill would let AI companies set their own rules for up to 10 years. The SANDBOX Act would let companies request exemptions from regulation for AI products and services — and let the White House override agencies that say no.

News photo

Psychological Tricks Can Get AI to Break the Rules

News photo

Already I'm convinced, Hollow Knight: Silksong is a hymn to the art of paying attention - and it absolutely rules