Traits for function items
Rust Internals [Unofficial]
July 2, 2026
peter-lyons-kehl:
Suggest Implementing traits on function pointers - #2 by steffahn - help - The Rust Programming Language Forum ---> " A possible workaround, using
unsafecode, could be to check for a zero-sized andCopytype that implementsFn
Looking back at my exact code from back then, I’m noticing that a zero-sized, Copy type might nonetheless still potentially
- carry a lifetime after which it must not be accessed anymore
- have
Sendrestrictions, i.e. that it cannot be used from a different thread.
Thus for soundness, besides the (annoyingly monomorphization-time) zero-sizedness check, and the F: Copy bound, I would also add an F: 'static bound[1] as well as a F: Send bound.
- even though this does preclude some cases where things would have been sound, such as some
fn foo<'a>(…) -> &'a Foofunction item instantiated for non-'staticlifetime ↩︎
Discussion in the ATmosphere