How to prevent an unused field to be optimized by compiler?

⚓ rust    📅 2025-06-04    👤 surdeus    👁️ 2      

surdeus

I have a struct that contains a field which is a handle to something else.
I use this handle to keep the resource from being dropped, but my code does not use that field.
But I found that in the release build, this field is optimized away by the compiler. What's the recommended way to resolve this?

5 posts - 4 participants

Read full topic

🏷️ rust_feed