Skip to content

Instantly share code, notes, and snippets.

@vijairaj
Forked from rust-play/playground.rs
Created December 12, 2018 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vijairaj/e037ec761a72b32533407904d0a12d80 to your computer and use it in GitHub Desktop.
Save vijairaj/e037ec761a72b32533407904d0a12d80 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
/// Methods
struct Point { x: i32, y: i32 }
impl Point {
fn from(x: i32, y: i32) -> Point { // Associated function = no self
Point { x, y }
}
fn tostr(&self) -> String { // Method takes self as param
format!("Point({}, {})", self.x, self.y)
}
}
fn main() {
let pt1 = Point::from(11, 12);
println!("val: {}", pt1.tostr());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment