Cannot call associate private function in tests

I create a mod that has a struct and some private functions impl for this struct, then in the same file I want to call these private functions in a tests mod but I got error of

associated function my_function is private

Why is this?

Privacy is defined by the module hierarchy, not just being in the same file. If your code and test modules are next to each other, like siblings, then the test module doesn't have private access. Usually, you should put tests in a submodule relative to the private definitions, if you bother adding that separation at all.

1 Like

It seems like is a better fit for this thread ( is for the development of Rust (the language) and associated tooling (e.g., the rustc compiler)).


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.