![[Rust Guide] 7.3. Path Pt. 2 - Accessing Parent Modules and Pub on Structs and Enums](/_next/image?url=https%3A%2F%2Fmedia2.dev.to%2Fdynamic%2Fimage%2Fwidth%3D1200%2Cheight%3D627%2Cfit%3Dcover%2Cgravity%3Dauto%2Cformat%3Dauto%2Fhttps%253A%252F%252Fdev-to-uploads.s3.amazonaws.com%252Fuploads%252Farticles%252F0nlqdiy9ziky4rk0dvio.png&w=1200&q=75)
[Rust Guide] 7.3. Path Pt. 2 - Accessing Parent Modules and Pub on Structs and Enums
If you find this helpful, please like, bookmark, and follow. To keep learning along, follow this series. 7.3.1 super We can access items in a parent module’s path by using super at the start of a path, just like using .. syntax to start a file-system path. For example: fn deliver_order () {} mod back_of_house { fn fix_incorrect_order () { cook_order (); super :: deliver_order (); } fn cook_order () {} } Of course, you can use an absolute path to achieve the same result: fn deliver_order () {} mod back_of_house { fn fix_incorrect_order () { cook_order (); crate :: deliver_order (); } fn cook_order () {} } 7.3.2 pub struct If you put the pub keyword before struct , the struct becomes public, as shown below: mod back_of_house { pub struct Breakfast { toast : String , seasonal_fruit : String , } } Note that although this struct is public, the fields inside a struct are private by default , unless you add the pub keyword. In Rust, in most cases if something does not have pub , then it is pr
Continue reading on Dev.to
Opens in a new tab



