Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. #[derive(Debug)]
  2. struct Vec2 {
  3. x: f32,
  4. y: f32
  5. }
  6.  
  7. impl Vec2 {
  8. pub fn new(x: f32, y: f32) -> Self {
  9. Vec2 {
  10. x,
  11. y
  12. }
  13. }
  14.  
  15. pub fn add(self, other: Vec2) -> Self {
  16. Vec2::new(self.x + other.x, self.y + other.y)
  17. }
  18.  
  19. pub fn sub(self, other: Vec2) -> Self {
  20. Vec2::new(self.x - other.x, self.y - other.y)
  21. }
  22. }
  23.  
  24. fn main() {
  25. let a = Vec2::new(10.0, 20.0)
  26. .add(Vec2::new(20.0, 20.0))
  27. .sub(Vec2::new(10.0, 20.0));
  28.  
  29. println!("Hello: {:?}", a);
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement