strum
strum copied to clipboard
Question about effect on memory allocation
Hi,
I'm looking to use this strum's #[derive(Display)]
feature, but I'm fairly new to rust and I'm not sure how this will affect memory allocation. Namely for a simple enumerations below, Thing
would allocated on the stack since it's of known size, and I was wondering if using the derive display method would cause Thing
to be moved to the heap. My guess is likely not, but I wanted to make sure:
#[derive(Display)]
enum Letters { A, B, C, D }
struct Thing { letters: Letters }
@dmr07 Letters
& Thing
will remain on stack. Only calling Letters::to_string
will allocate memory on heap for the output string. However, you can use #[derive(IntoStaticStr)]
to avoid allocations altogether.
@dmr07, it looks like your question was answered so I'm going to close this, but feel free to re-open if needed.