Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #[derive(Debug)]
- struct Vec2 {
- x: f32,
- y: f32
- }
- impl Vec2 {
- pub fn new(x: f32, y: f32) -> Self {
- Vec2 {
- x,
- y
- }
- }
- pub fn add(self, other: Vec2) -> Self {
- Vec2::new(self.x + other.x, self.y + other.y)
- }
- pub fn sub(self, other: Vec2) -> Self {
- Vec2::new(self.x - other.x, self.y - other.y)
- }
- }
- fn main() {
- let a = Vec2::new(10.0, 20.0)
- .add(Vec2::new(20.0, 20.0))
- .sub(Vec2::new(10.0, 20.0));
- println!("Hello: {:?}", a);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement