Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // We use mod to create a non-public block
- mod lib {
- pub struct Car;
- impl Car {
- // Public method
- pub fn run(& self) {
- // Call private method
- self.drive();
- }
- }
- impl Car {
- // Private method
- fn drive(& self) {
- println!("Driving a car...");
- }
- }
- }
- fn main() {
- let car = lib::Car{};
- car.run();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement