Re:Type Inference That Sticks
by lambdaxymox on Sunday February 05, 2023 @12:06PM
(#34666518)
Type inference occasionally bites one's hand when pushing data across an FFI boundary. In one instance I was writing some graphics code for a project and for some reason the colors in the rendering model were coming out all wrong on the screen (TL;DR it ended up looking like two of the color channels were missing from some texture maps) and it turns out that Rust inferred the type of the buffer as a vector of f64s instead of a vector of f32s. Putting the type in specifically fixed the problem promptly.
Lesson learned: Sometimes type inference fails, and always annotate your types at FFI boundaries!
Re:Type Inference That Sticks
by brundolf on Sunday February 05, 2023 @12:33PM
(#34666759)
Yeah, it's important to annotate anything that interacts with the outside world, because that code/API isn't available for the compiler to reason about before run-time. Same goes with HTTP endpoints (on both the client and the server)
Lesson learned: Sometimes type inference fails, and always annotate your types at FFI boundaries!