1

I have an exercise library to learn Rust. This library provides two kinds of methods:

  1. core methods which should be in a file called renderay_core.rs.
  2. shape methods which use the core methods to have a higher abstraction/more concrete implementation of the core methods; convenience methods for "often used" cases. These should be in a file called renderay_shapes.rs.

I also want to have unit tests in them as submodules.

I thought of something like:

  • renderay.rs is the library source [lib] path="src/renderay.rs"
  • renderay_core.rs is a module which is loaded into renderay.rs as public(?) to yield its API
  • renderay_shapes.rs is also a module within renderay.rs but also imports renderay_core.rs to its core API

If I load this crate as a dependency, I would like to have the API of renderay_core.rs and renderay_shapes.rs available.

I'm sure it is a trivial task, but I have a hard time getting my head around the module mechanics coming from Java and C. I already read the crates and modules documentation. How to setup such a structure and compile it successfully?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
xetra11
  • 7,671
  • 14
  • 84
  • 159
  • 2
    Why do you care what the file names are? Why not just `src/lib.rs`, `src/core.rs` and `src/shapes.rs`; the crate is called *renderay*, and the modules would be at `renderay::core`? – Shepmaster Aug 23 '16 at 19:36
  • And what about shapes.rs ? how should I import core? use renderay::core ? – xetra11 Aug 23 '16 at 20:27
  • 2
    [How do I import from a sibling module?](http://stackoverflow.com/q/30677258/155423); [How do you use parent module imports in rust?](http://stackoverflow.com/q/20922091/155423); [Split implementation across multiple files/modules and keep everything as private as possible](http://stackoverflow.com/q/36021619/155423); [How can I use shared logic from different files?](http://stackoverflow.com/q/30286861/155423). – Shepmaster Aug 23 '16 at 20:30
  • thank you - didn't had the right keywords for those results! – xetra11 Aug 23 '16 at 20:48

0 Answers0