I am new at Rust, come from 4y+ exp of Go, so, maybe my problems comes from my brain that is not fully adapted yet for rust. Whatever.
I trying to rewrite my own error-logging Go framework on Rust as my pet-project.
It is a shortened gist (don't want to paste it as a part of message, there 200+ lines).
It's a first part of error module. There are error's namespaces, classes, etc. Gist contains only those code that is necessary to build this example.
So, there are tests submodule to run tests and main func to run as a binary.
If I run a test like
cargo test class_get -- --nocapture sometimes it leads to
Namespace: "Common", ID: 1 ekaru_test-16fc58a13eeab6a4(10944,0x70000e3f3000) malloc: *** error for object 0xa600a1ffff009c: pointer being freed was not allocated ekaru_test-16fc58a13eeab6a4(10944,0x70000e3f3000) malloc: *** set a breakpoint in malloc_error_break to debug
ofc addresses are vary.
Because of output (there only 1st is printed of 2 expected), I guess there is some problem in representing
Class as string and generate that format string. Something trying to be freed that should not. And I don't understand what. And how may I fix that.
Moreover. I run both of test (using command above) and binary in both of envs: debug, release. A lot of times. Both with and w/o recompilation. I never got that error if I run a binary. That's very strange (for me) even more.
So, I have one general question and one additional.
What goes wrong? Why? And how may I fix that or avoid?
You may notice an unsafe function with an expected name. It does one unforgivable thing. & -> &mut.
I may guarantee that it's OK, cause using that function it overwrites a different parts of RAM, because it's a vector and each time it addresses to different pieces (because of atomic inc). And it's a vector that will never move nor its data (caused by growth). It will never grow.
However, I think, it's bad. I think, I should not do that. Does I have a way achieve what I want somehow not violating a rule that is prohibited even by nomicon? Or it's the only way?
rustc 1.49.0, macOS 11.4