객체지향 프로그래밍

함수형 프로그래밍

제네릭

연산자 재정의

오버헤드가 (거의) 없는 메모리 관리

오버헤드가 (거의) 없는 추상화


Rust를 합시다.

use std::ops::{Add, AddAssign};
#[derive(Debug)]
struct Point {
x: i32,
y: i32,
}

impl Add<i32> for Point {
type Output = Point;
fn add(self, other: i32) -> Point {
Point {
x: self.x + other,
y: self.y + other,
}
}
}
impl AddAssign<i32> for Point {
fn add_assign(&mut self, other: i32) {
self.x += other;
self.y += other;
}
}
impl Add for Point {
type Output = Point;
fn add(self, other: Point) -> Point {
Point {
x: self.x + other.x,
y: self.y + other.y,
}
}
}
fn main() {
let pt = Point{x:0, y:0};
println!("{:?}",pt);
let pt = pt + Point{x:5,y:10};
println!("{:?}",pt);
let pt = pt + 5;
println!("{:?}",pt);
}