Skip to main content

extract_fn_trait_args

Function extract_fn_trait_args 

Source
pub fn extract_fn_trait_args(ty: &Type) -> Option<Vec<Type>>
Expand description

If ty is impl Fn(T1, T2, ...) + Send + Sync + 'static, return the Fn argument types in declaration order. Otherwise None.

A callback returns nothing, and that is checked, not assumed: a written -> () is the same thing spelled out, and any other return is refused. TypeKind::Callback has no slot for one, so accepting impl Fn() -> u8 would drop a fact a destination language needs — and drop it silently, which is worse than the refusal.

The callback grammar, and the language’s alone: TypeKind::Callback is exactly what this accepts, so acceptance cannot drift from classification. The registry re-exports it for the consumers that have not migrated yet.