blob: a25704412262ddd8175cb56eb64db0368e46b46c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
use std::cmp::PartialEq;
use std::ops::{Add, Sub, Mul};
pub trait MyNum : Add<Output=Self> + Sub<Output=Self> + Mul<Output=Self> + PartialEq + Clone {
}
#[derive(Clone, Debug)]
pub struct MyInt {
pub val: isize
}
impl Add for MyInt {
type Output = MyInt;
fn add(self, other: MyInt) -> MyInt { mi(self.val + other.val) }
}
impl Sub for MyInt {
type Output = MyInt;
fn sub(self, other: MyInt) -> MyInt { mi(self.val - other.val) }
}
impl Mul for MyInt {
type Output = MyInt;
fn mul(self, other: MyInt) -> MyInt { mi(self.val * other.val) }
}
impl PartialEq for MyInt {
fn eq(&self, other: &MyInt) -> bool { self.val == other.val }
fn ne(&self, other: &MyInt) -> bool { !self.eq(other) }
}
impl MyNum for MyInt {}
fn mi(v: isize) -> MyInt { MyInt { val: v } }
|