Crate box_closure

Crate box_closure 

Source
Expand description

Wrappers over Fn, FnMut, and FnOnce that simplify dispatching closures when alloc isn’t available.

Typical closures are confusing, rustc treats them as unique even if they’re identical. The closure types in box_closure are only opaque; rustc can’t see through them and as long as the signitures match, they’re treated as being the same closure.

This is effectively what Box<dyn Fn ... > does, but without allocating a Box. For embedded development, heap allocation is not usually an option, so box_closure replaces the need to box closures, instead allowing you to wrap them in OpaqueFn, OpaqueFnMut, or OpaqueFnOnce types to stop rustc from complaining about opaque types.

By being more opaque, box_closure stops opaque type compiler errors when dispatching closures.

Structs§

Align1
A statically sized buffer aligned to 1 byte.
Align2
A statically sized buffer aligned to 2 bytes.
Align4
A statically sized buffer aligned to 4 bytes.
Align8
A statically sized buffer aligned to 8 bytes.
Align16
A statically sized buffer aligned to 16 bytes.
Align32
A statically sized buffer aligned to 32 bytes.
Align64
A statically sized buffer aligned to 64 bytes.
OpaqueFn
A fixed-capacity inline function wrapper without allocation.
OpaqueFnMut
A fixed-capacity inline function wrapper without allocation.
OpaqueFnOnce
A fixed-capacity inline function wrapper without allocation.