Is `struct Dip(f32)` always as fast as `f32`?

⚓ Rust    📅 2025-06-07    👤 surdeus    👁️ 5      

surdeus

Warning

This post was published 64 days ago. The information described in this article may have changed.

I have some UI layout code, and I was thinking of creating a new type to help keep my units straight.

/// Device independent pixels
struct Dip(f32)
impl Add for Dip { ... }
impl Mul for Dip { ... }
...

Is this always going to be as fast as raw f32? I remember a C++ talk called something like "There are no zero cost abstractions".

7 posts - 6 participants

Read full topic

🏷️ rust_feed