1. 33
    Rustlings modules2: Defining public interfaces for nested modules
    57s

Rustlings modules2: Defining public interfaces for nested modules

Chris Biscardi
InstructorChris Biscardi
Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 3 years ago

README for this exercise.

Chris Biscardi: [0:00] In modules2, we have a delicious_snacks module that uses self: :fruits: :PEAR as fruit; and self: :veggies: :CUCUMBER as veggie;. You can see that inside of this module we have an additional module called fruits and additional module called veggies, which is what these use statements refer to.

[0:14] Inside of our fruit and veggie modules, we have pub const PEAR, APPLE, CUCUMBER, and CARROT. These constants are string slices with static lifetimes. In our main function we use the println! Macro to print our favorite snacks which are delicious_snacks: :fruit and delicious_snacks: :veggie.

[0:30] The Rust compiler tells us that the constant import 'fruit' is private inside of the delicious snacks module. One way we can solve this is by making our use statements public inside of the delicious_snacks module. This exposes each of the individual constants, but not the other ones involved in the fruits and veggies modules.

[0:50] Now, in the end, we have our delicious_snacks module that exports a different interface than the internal fruits and veggies modules.

egghead
egghead
~ 49 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today