Is it possible to share functions between two Rust libraries, but not make them public, ie visible from binaries?
For example, I have two libraries.
- Lib A contains two functions, one of which is public, the other is not (f1)
- Lib B can use the public function of Lib A, and it wants to use the private function (f1) of Lib A also, but can't
- Components M, N, O, ... etc ..., use both Lib A and Lib B. Although Lib B should be able to see f1 from Lib A, I don't want the components M, N, O, ..., to be able to see f1 directly. They need to use f1 only via the public functions of Lib B... (Or Lib A)
Valid function calls might look like this:
Component M -> LibA:: pub fn funcA
Component N -> LibB:: pub fn funcAA -> LibA:: pub fn funcA
Component O -> LibB:: pub fn funcAA -> LibA:: (private) fn funcB
But this would not be valid:
Component M -> LibA:: (private) fn funcB
I would guess the answer to this is no, and that I would have to combine both my Lib A and Lib B into a single library, most likely by adding an additional module layer.
This is not ideal because Lib A and Lib B accomplish the same job but with very different APIs. It should NOT be possible to mix the functions from Lib A with function calls from Lib B. On an abstract level, they are supposed to represent very different concepts / methods of doing something.
In some sense, imagine that Lib A and Lib B present two very different APIs for interacting with a database.
Lib B is essentially a higher order wrapper around Lib A. They do the same things, ultimately, but can't be mixed together.