Re:Using enums to represent state in Rust
by tialaramex on Saturday September 23, 2023 @08:01AM
(#37622493)
That's not inference, you're literally telling callers "the object I'm giving you might have any type but I promise it implements this Trait".
The compiler knows which concrete type it is, but you needn't and your caller isn't promised it is any particular type (but it is, they just aren't allowed to care)
This is useful because all Rust's functions are types, both lambda and ordinary functions are unique types, but we often want to say I'm going to return say a predicate - we can't name the predicate we're going to return but our caller just wants a predicate so they don't care that we couldn't spell its name.
(I wouldn’t count impl trait in function parameters since that acts more like a generic type.)