Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Post History

60%
+1 −0
Q&A Rust golfing tips

Avoid type annotations with a closure instead of a fn Function (24 bytes) A function requires types to be specified for its return value, and for any arguments it takes. fn f(a:u8,b:u8)->u8{a...

posted 8d ago by trichoplax‭

Answer
#1: Initial revision by user avatar trichoplax‭ · 2025-04-10T17:14:05Z (8 days ago)
## Avoid type annotations with a closure instead of a fn

### Function (24 bytes)
A function requires types to be specified for its return value, and for any arguments it takes.

```rust
fn f(a:u8,b:u8)->u8{a*b}
```

[Test function on Rust Playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=cc81277be514fb2357174770ab0fa565)

### Closure (15 bytes)

A closure does not generally require types to be specified for either its return value or any arguments it takes.

```rust
let f=|a,b|a*b;
```

[Test closure on Rust Playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=50791b04366d0a380af84b3b483affb4)