use assoc types in binop traits

This commit is contained in:
Jorge Aparicio
2014-12-31 15:45:13 -05:00
parent 7095dd0070
commit 99017f82b6
36 changed files with 375 additions and 156 deletions

View File

@@ -53,13 +53,17 @@ impl Pos for BytePos {
fn to_uint(&self) -> uint { let BytePos(n) = *self; n as uint }
}
impl Add<BytePos, BytePos> for BytePos {
impl Add for BytePos {
type Output = BytePos;
fn add(self, rhs: BytePos) -> BytePos {
BytePos((self.to_uint() + rhs.to_uint()) as u32)
}
}
impl Sub<BytePos, BytePos> for BytePos {
impl Sub for BytePos {
type Output = BytePos;
fn sub(self, rhs: BytePos) -> BytePos {
BytePos((self.to_uint() - rhs.to_uint()) as u32)
}
@@ -70,13 +74,17 @@ impl Pos for CharPos {
fn to_uint(&self) -> uint { let CharPos(n) = *self; n }
}
impl Add<CharPos, CharPos> for CharPos {
impl Add for CharPos {
type Output = CharPos;
fn add(self, rhs: CharPos) -> CharPos {
CharPos(self.to_uint() + rhs.to_uint())
}
}
impl Sub<CharPos, CharPos> for CharPos {
impl Sub for CharPos {
type Output = CharPos;
fn sub(self, rhs: CharPos) -> CharPos {
CharPos(self.to_uint() - rhs.to_uint())
}