rust - How to define a multi level crate? -


i'm trying define crate going along rust application explained in documentation. let's take following directory structure:

src/ ├─ lib.rs ├─ main.rs └─ myapp/   ├─ a/   │ ├─ a1.rs   │ └─ mod.rs   └─ mod.rs 

now defined following in rust files:

lib.rs

pub mod myapp; 

main.rs

extern crate myapp; use myapp::a;  fn main() {     unimplemented!(); } 

myapp/mod.rs

pub mod a; 

myapp/a/mod.rs

pub use self::a1::*; mod a1; 

myapp/a/a1.rs

pub fn myfunc() {     unimplemented!(); } 

if try compile above directory tree, got error:

$ cargo build compiling myapp v0.1.0 src/main.rs:2:5: 2:13 error: unresolved import `myapp::a`. there no `a` in `myapp` [e0432] src/main.rs:2 use myapp::a;                   ^~~~~~~~ src/main.rs:2:5: 2:13 help: run `rustc --explain e0432` see detailed explanation error: aborting due previous error not compile `myapp`. 

where wrong here? think have same directory structure 1 shown in documentation.

you've added level of nesting. main works if change be

extern crate myapp; use myapp::myapp::a;  fn main() {     unimplemented!(); } 

crates form own level in path, first myapp refers crate, second myapp refers module you've created.

on side note, it's rare see crate level of nesting , bifurcation. rust crates tend have larger chunks of code per file, , not one-struct-per-file common in other languages. in experience, of course, , isn't hard-and-fast rule.


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -