0

I have a project which contains three files main.rs,bytes.rs and provider.rs. I have created mod.rs file and I have included both crate bytes.rs and provider.rs as shown below. whenever I am trying to include mod bytes inside the provider.rs, I get the error, please help me to sort out this.

error: file not found for module bytes

 ---projectA
      + src
       --   main.rs
       --   mod.rs
       --   bytes.rs
       --   provider.rs
nagaraj
  • 797
  • 1
  • 6
  • 29

1 Answers1

0

I have created mod.rs file

That was completely unnecessary:

  1. mod.rs is only for subfolders of the root folder. For the root, there is already a crate root (main.rs or lib.rs) so there is no situation in which this file is useful
  2. and in edition 2018 mod.rs is not necessary for sub-mods to work (though it is still allowed I think)

You should just have mod bytes; mod provider in the crate root (main.rs). Then, provider.rs can either:

  • use the item from bytes directly e.g. super::bytes::... or crate::bytes::... will resolve to the relevant symbol from the bytes sibling module
  • use a similar path in order to use "short forms" for symbols e.g. use super::bytes::Foo will let the module refer to Foo without needing the fully qualified path

See https://stackoverflow.com/a/30687811/8182118 for more, as well as a description of edition 2015.

Masklinn
  • 34,759
  • 3
  • 38
  • 57