book icon indicating copy to clipboard operation
book copied to clipboard

Accessing code in `src/lib.rs` from `src/main.rs`

Open c-git opened this issue 3 years ago • 1 comments

  • [X] I have checked the latest main branch to see if this has already been fixed
  • [X] I have searched existing issues and pull requests for duplicates

I wasn't really sure how to compose my search terms. And didn't find anything relating to what I wanted to talk about.

URL to the section(s) of the book with this problem:

https://doc.rust-lang.org/stable/book/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.html#best-practices-for-packages-with-a-binary-and-a-library

Description of the problem:

I'm not sure I would call it a problem per se. Rather a suggestion to make using the book as a quick reference more practical. I recently finished the book (fully disclosure, due to time constraints did not do all the exercises while reading it), and realized the at the end of it when I tried to do a project and split my code between src/main.rs and src/lib.rs, I couldn't figure out how to "access" to the code I had put in src/lib.rs. I tried looking through the book for the answer and I did look at the section referenced by the link but due to skimming and trying to find what I was looking for I did not see the text that said "...by starting paths with the name of the package."

Suggested fix:

I was going to write a short code snippet to make it easier to find but haven't had a chance to do so. But I decided it might be better for me to create an issue and find out if this is even something that would be desirable before I invest the time in writing the code snippet and submitting a pull request.

I was thinking of putting the code snippet right after the paragraph that talks about how to do it. I know it says that there is an example in chapter 12 (which there is) but it's not where I would look for that information based on the table of contents.

c-git avatar Aug 24 '22 16:08 c-git

Is there value in keeping this issue open?

c-git avatar Jan 03 '25 01:01 c-git