These impls, at least, can be avoided by deriving Ord.

This commit is contained in:
Lindsey Kuper 2013-09-14 19:37:39 -04:00
parent 653ffa845d
commit 6ba2cb88a6

View File

@ -30,12 +30,12 @@ pub trait Pos {
}
/// A byte offset
#[deriving(Clone, Eq, IterBytes)]
#[deriving(Clone, Eq, IterBytes, Ord)]
pub struct BytePos(uint);
/// A character offset. Because of multibyte utf8 characters, a byte offset
/// is not equivalent to a character offset. The CodeMap will convert BytePos
/// values to CharPos values as necessary.
#[deriving(Eq,IterBytes)]
#[deriving(Eq,IterBytes, Ord)]
pub struct CharPos(uint);
// XXX: Lots of boilerplate in these impls, but so far my attempts to fix
@ -46,13 +46,6 @@ fn from_uint(n: uint) -> BytePos { BytePos(n) }
fn to_uint(&self) -> uint { **self }
}
impl cmp::Ord for BytePos {
fn lt(&self, other: &BytePos) -> bool { **self < **other }
fn le(&self, other: &BytePos) -> bool { **self <= **other }
fn ge(&self, other: &BytePos) -> bool { **self >= **other }
fn gt(&self, other: &BytePos) -> bool { **self > **other }
}
impl Add<BytePos, BytePos> for BytePos {
fn add(&self, rhs: &BytePos) -> BytePos {
BytePos(**self + **rhs)
@ -70,13 +63,6 @@ fn from_uint(n: uint) -> CharPos { CharPos(n) }
fn to_uint(&self) -> uint { **self }
}
impl cmp::Ord for CharPos {
fn lt(&self, other: &CharPos) -> bool { **self < **other }
fn le(&self, other: &CharPos) -> bool { **self <= **other }
fn ge(&self, other: &CharPos) -> bool { **self >= **other }
fn gt(&self, other: &CharPos) -> bool { **self > **other }
}
impl Add<CharPos,CharPos> for CharPos {
fn add(&self, rhs: &CharPos) -> CharPos {
CharPos(**self + **rhs)