daily pastebin goal
14%
SHARE
TWEET

[Rust] public and private methods

cwchen Aug 28th, 2017 339 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
  1. // We use mod to create a non-public block
  2. mod lib {
  3.     pub struct Car;
  4.  
  5.     impl Car {
  6.         // Public method
  7.         pub fn run(& self) {
  8.             // Call private method
  9.             self.drive();
  10.         }
  11.     }
  12.  
  13.     impl Car {
  14.         // Private method
  15.         fn drive(& self) {
  16.             println!("Driving a car...");
  17.         }
  18.     }
  19. }
  20.  
  21. fn main() {
  22.     let car = lib::Car{};
  23.     car.run();
  24. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top