Application construction and libraries

When writing an application, should libraries be dependent on each other. What is the usual way of Rust workflows? Examples of what I mean

Main
lib1
lib2

Should main contact lib1 to either perform an action or return output so that main gets a Result of "Ok" or gets a value returned. Then, main uses lib2 with any output from lib1, if there is output.

Or

Is it acceptable for lib1 to use lib2 to perform an action or get output and lib1 returns that result to main.

There is no broad design rule that says you should do one or the other. It all depends on the details of the actual problem. Avoid over-engineering; write something that works and be prepared to change it later.

That said, if you anticipate the program growing so large it is slow to compile, then designing so that lib1 does not depend on lib2 will help the overall build time since lib1 and lib2 can be compiled in parallel and changing one won't affect the other.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.