Drop::drop() scope?

I'm trying to figure out why the destructor for a struct runs during a #[test], but not when that struct gets allocated outside that module.

Can you elaborate on what you mean by "allocated outside that module"?

1 Like

Never mind... I wasn't getting far enough in my testing to actually initialize the struct. I've been building this thing to run #[tests] after posting this question. As it always is: once one asks a question, one inevitably stumbles on other ways to get to the answer.


There are two modules: main and struct. #[tests] for both ran and saved the struct. It wasn't until asking the question that I realized I had #[test] for main; which successfully allocated and saved the struct. When running the program outside #[test], the struct was never saved, which seemed quite odd until realizing that the cli invocation never got far enough to allocate the struct.

I think what's happening is that the drop() for the struct member (a moka cache) is called before my drop(). It doesn't happen all the time. It doesn't look like there's a way to intercept the moka cache drop() and add serialization code.