Replace some Eq impls with deriving_eq
This commit is contained in:
parent
742f354ffb
commit
d809e89c26
13 changed files with 24 additions and 263 deletions
|
@ -240,6 +240,8 @@ mod core {
|
||||||
pub const warn : u32 = 2_u32;
|
pub const warn : u32 = 2_u32;
|
||||||
pub const info : u32 = 3_u32;
|
pub const info : u32 = 3_u32;
|
||||||
pub const debug : u32 = 4_u32;
|
pub const debug : u32 = 4_u32;
|
||||||
|
|
||||||
|
pub use cmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ use cmp::Eq;
|
||||||
use result::Result;
|
use result::Result;
|
||||||
|
|
||||||
/// The either type
|
/// The either type
|
||||||
|
#[deriving_eq]
|
||||||
pub enum Either<T, U> {
|
pub enum Either<T, U> {
|
||||||
Left(T),
|
Left(T),
|
||||||
Right(U)
|
Right(U)
|
||||||
|
@ -141,26 +142,6 @@ pub pure fn unwrap_right<T,U>(eith: Either<T,U>) -> U {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T:Eq,U:Eq> Either<T,U> : Eq {
|
|
||||||
pure fn eq(&self, other: &Either<T,U>) -> bool {
|
|
||||||
match (*self) {
|
|
||||||
Left(ref a) => {
|
|
||||||
match (*other) {
|
|
||||||
Left(ref b) => (*a).eq(b),
|
|
||||||
Right(_) => false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Right(ref a) => {
|
|
||||||
match (*other) {
|
|
||||||
Left(_) => false,
|
|
||||||
Right(ref b) => (*a).eq(b)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pure fn ne(&self, other: &Either<T,U>) -> bool { !(*self).eq(other) }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_either_left() {
|
fn test_either_left() {
|
||||||
let val = Left(10);
|
let val = Left(10);
|
||||||
|
|
|
@ -445,24 +445,9 @@ pub mod rt {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[deriving_eq]
|
||||||
pub enum PadMode { PadSigned, PadUnsigned, PadNozero, PadFloat }
|
pub enum PadMode { PadSigned, PadUnsigned, PadNozero, PadFloat }
|
||||||
|
|
||||||
pub impl PadMode : Eq {
|
|
||||||
pure fn eq(&self, other: &PadMode) -> bool {
|
|
||||||
match ((*self), (*other)) {
|
|
||||||
(PadSigned, PadSigned) => true,
|
|
||||||
(PadUnsigned, PadUnsigned) => true,
|
|
||||||
(PadNozero, PadNozero) => true,
|
|
||||||
(PadFloat, PadFloat) => true,
|
|
||||||
(PadSigned, _) => false,
|
|
||||||
(PadUnsigned, _) => false,
|
|
||||||
(PadNozero, _) => false,
|
|
||||||
(PadFloat, _) => false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pure fn ne(&self, other: &PadMode) -> bool { !(*self).eq(other) }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn pad(cv: Conv, s: ~str, mode: PadMode) -> ~str {
|
pub fn pad(cv: Conv, s: ~str, mode: PadMode) -> ~str {
|
||||||
let mut s = move s; // sadtimes
|
let mut s = move s; // sadtimes
|
||||||
let uwidth : uint = match cv.width {
|
let uwidth : uint = match cv.width {
|
||||||
|
|
|
@ -523,18 +523,9 @@ pub pure fn with_str_reader<T>(s: &str, f: fn(Reader) -> T) -> T {
|
||||||
pub enum FileFlag { Append, Create, Truncate, NoFlag, }
|
pub enum FileFlag { Append, Create, Truncate, NoFlag, }
|
||||||
|
|
||||||
// What type of writer are we?
|
// What type of writer are we?
|
||||||
|
#[deriving_eq]
|
||||||
pub enum WriterType { Screen, File }
|
pub enum WriterType { Screen, File }
|
||||||
|
|
||||||
pub impl WriterType : Eq {
|
|
||||||
pure fn eq(&self, other: &WriterType) -> bool {
|
|
||||||
match ((*self), (*other)) {
|
|
||||||
(Screen, Screen) | (File, File) => true,
|
|
||||||
(Screen, _) | (File, _) => false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pure fn ne(&self, other: &WriterType) -> bool { !(*self).eq(other) }
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME (#2004): Seekable really should be orthogonal.
|
// FIXME (#2004): Seekable really should be orthogonal.
|
||||||
// FIXME (#2004): eventually u64
|
// FIXME (#2004): eventually u64
|
||||||
/// The raw underlying writer trait. All writers must implement this.
|
/// The raw underlying writer trait. All writers must implement this.
|
||||||
|
|
|
@ -47,6 +47,7 @@ let unwrapped_msg = match move msg {
|
||||||
use cmp::Eq;
|
use cmp::Eq;
|
||||||
|
|
||||||
/// The option type
|
/// The option type
|
||||||
|
#[deriving_eq]
|
||||||
pub enum Option<T> {
|
pub enum Option<T> {
|
||||||
None,
|
None,
|
||||||
Some(T),
|
Some(T),
|
||||||
|
@ -310,27 +311,6 @@ impl<T: Copy> Option<T> {
|
||||||
pure fn while_some(blk: fn(v: T) -> Option<T>) { while_some(self, blk) }
|
pure fn while_some(blk: fn(v: T) -> Option<T>) { while_some(self, blk) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Eq> Option<T> : Eq {
|
|
||||||
pure fn eq(&self, other: &Option<T>) -> bool {
|
|
||||||
match (*self) {
|
|
||||||
None => {
|
|
||||||
match (*other) {
|
|
||||||
None => true,
|
|
||||||
Some(_) => false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some(ref self_contents) => {
|
|
||||||
match (*other) {
|
|
||||||
None => false,
|
|
||||||
Some(ref other_contents) =>
|
|
||||||
(*self_contents).eq(other_contents)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pure fn ne(&self, other: &Option<T>) -> bool { !(*self).eq(other) }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_unwrap_ptr() {
|
fn test_unwrap_ptr() {
|
||||||
let x = ~0;
|
let x = ~0;
|
||||||
|
|
|
@ -20,6 +20,7 @@ Cross-platform file path handling
|
||||||
|
|
||||||
use cmp::Eq;
|
use cmp::Eq;
|
||||||
|
|
||||||
|
#[deriving_eq]
|
||||||
pub struct WindowsPath {
|
pub struct WindowsPath {
|
||||||
host: Option<~str>,
|
host: Option<~str>,
|
||||||
device: Option<~str>,
|
device: Option<~str>,
|
||||||
|
@ -31,6 +32,7 @@ pub pure fn WindowsPath(s: &str) -> WindowsPath {
|
||||||
from_str(s)
|
from_str(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[deriving_eq]
|
||||||
pub struct PosixPath {
|
pub struct PosixPath {
|
||||||
is_absolute: bool,
|
is_absolute: bool,
|
||||||
components: ~[~str],
|
components: ~[~str],
|
||||||
|
@ -356,24 +358,6 @@ impl PosixPath : ToStr {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PosixPath : Eq {
|
|
||||||
pure fn eq(&self, other: &PosixPath) -> bool {
|
|
||||||
return (*self).is_absolute == (*other).is_absolute &&
|
|
||||||
(*self).components == (*other).components;
|
|
||||||
}
|
|
||||||
pure fn ne(&self, other: &PosixPath) -> bool { !(*self).eq(other) }
|
|
||||||
}
|
|
||||||
|
|
||||||
impl WindowsPath : Eq {
|
|
||||||
pure fn eq(&self, other: &WindowsPath) -> bool {
|
|
||||||
return (*self).host == (*other).host &&
|
|
||||||
(*self).device == (*other).device &&
|
|
||||||
(*self).is_absolute == (*other).is_absolute &&
|
|
||||||
(*self).components == (*other).components;
|
|
||||||
}
|
|
||||||
pure fn ne(&self, other: &WindowsPath) -> bool { !(*self).eq(other) }
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME (#3227): when default methods in traits are working, de-duplicate
|
// FIXME (#3227): when default methods in traits are working, de-duplicate
|
||||||
// PosixPath and WindowsPath, most of their methods are common.
|
// PosixPath and WindowsPath, most of their methods are common.
|
||||||
impl PosixPath : GenericPath {
|
impl PosixPath : GenericPath {
|
||||||
|
|
|
@ -518,6 +518,7 @@ fn test_repr2() {
|
||||||
|
|
||||||
// Old non-factored implementation, transitional...
|
// Old non-factored implementation, transitional...
|
||||||
|
|
||||||
|
#[deriving_eq]
|
||||||
enum EnumVisitState {
|
enum EnumVisitState {
|
||||||
PreVariant, // We're before the variant we're interested in.
|
PreVariant, // We're before the variant we're interested in.
|
||||||
InVariant, // We're inside the variant we're interested in.
|
InVariant, // We're inside the variant we're interested in.
|
||||||
|
@ -525,13 +526,6 @@ enum EnumVisitState {
|
||||||
Degenerate // This is a degenerate enum (exactly 1 variant)
|
Degenerate // This is a degenerate enum (exactly 1 variant)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EnumVisitState : cmp::Eq {
|
|
||||||
pure fn eq(&self, other: &EnumVisitState) -> bool {
|
|
||||||
((*self) as uint) == ((*other) as uint)
|
|
||||||
}
|
|
||||||
pure fn ne(&self, other: &EnumVisitState) -> bool { !(*self).eq(other) }
|
|
||||||
}
|
|
||||||
|
|
||||||
struct EnumState {
|
struct EnumState {
|
||||||
end_ptr: *c_void,
|
end_ptr: *c_void,
|
||||||
state: EnumVisitState
|
state: EnumVisitState
|
||||||
|
|
|
@ -19,6 +19,7 @@ use cmp::Eq;
|
||||||
use either::Either;
|
use either::Either;
|
||||||
|
|
||||||
/// The result type
|
/// The result type
|
||||||
|
#[deriving_eq]
|
||||||
pub enum Result<T, U> {
|
pub enum Result<T, U> {
|
||||||
/// Contains the successful result value
|
/// Contains the successful result value
|
||||||
Ok(T),
|
Ok(T),
|
||||||
|
@ -374,26 +375,6 @@ pub fn unwrap_err<T, U>(res: Result<T, U>) -> U {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T:Eq,U:Eq> Result<T,U> : Eq {
|
|
||||||
pure fn eq(&self, other: &Result<T,U>) -> bool {
|
|
||||||
match (*self) {
|
|
||||||
Ok(ref e0a) => {
|
|
||||||
match (*other) {
|
|
||||||
Ok(ref e0b) => *e0a == *e0b,
|
|
||||||
_ => false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(ref e0a) => {
|
|
||||||
match (*other) {
|
|
||||||
Err(ref e0b) => *e0a == *e0b,
|
|
||||||
_ => false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pure fn ne(&self, other: &Result<T,U>) -> bool { !(*self).eq(other) }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[allow(non_implicitly_copyable_typarams)]
|
#[allow(non_implicitly_copyable_typarams)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
|
@ -55,6 +55,7 @@ pub enum Task {
|
||||||
TaskHandle(task_id)
|
TaskHandle(task_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// XXX: deriving
|
||||||
impl Task : cmp::Eq {
|
impl Task : cmp::Eq {
|
||||||
pure fn eq(&self, other: &Task) -> bool { *(*self) == *(*other) }
|
pure fn eq(&self, other: &Task) -> bool { *(*self) == *(*other) }
|
||||||
pure fn ne(&self, other: &Task) -> bool { !(*self).eq(other) }
|
pure fn ne(&self, other: &Task) -> bool { !(*self).eq(other) }
|
||||||
|
|
|
@ -79,16 +79,20 @@ use core::result::{Err, Ok};
|
||||||
use core::option;
|
use core::option;
|
||||||
use core::option::{Some, None};
|
use core::option::{Some, None};
|
||||||
|
|
||||||
|
#[deriving_eq]
|
||||||
enum Name {
|
enum Name {
|
||||||
Long(~str),
|
Long(~str),
|
||||||
Short(char),
|
Short(char),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[deriving_eq]
|
||||||
enum HasArg { Yes, No, Maybe, }
|
enum HasArg { Yes, No, Maybe, }
|
||||||
|
|
||||||
|
#[deriving_eq]
|
||||||
enum Occur { Req, Optional, Multi, }
|
enum Occur { Req, Optional, Multi, }
|
||||||
|
|
||||||
/// A description of a possible option
|
/// A description of a possible option
|
||||||
|
#[deriving_eq]
|
||||||
pub struct Opt {
|
pub struct Opt {
|
||||||
name: Name,
|
name: Name,
|
||||||
hasarg: HasArg,
|
hasarg: HasArg,
|
||||||
|
@ -102,49 +106,6 @@ fn mkname(nm: &str) -> Name {
|
||||||
} else { Long(unm) };
|
} else { Long(unm) };
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Name : Eq {
|
|
||||||
pure fn eq(&self, other: &Name) -> bool {
|
|
||||||
match (*self) {
|
|
||||||
Long(ref e0a) => {
|
|
||||||
match (*other) {
|
|
||||||
Long(ref e0b) => e0a == e0b,
|
|
||||||
_ => false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Short(e0a) => {
|
|
||||||
match (*other) {
|
|
||||||
Short(e0b) => e0a == e0b,
|
|
||||||
_ => false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pure fn ne(&self, other: &Name) -> bool { !(*self).eq(other) }
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Occur : Eq {
|
|
||||||
pure fn eq(&self, other: &Occur) -> bool {
|
|
||||||
((*self) as uint) == ((*other) as uint)
|
|
||||||
}
|
|
||||||
pure fn ne(&self, other: &Occur) -> bool { !(*self).eq(other) }
|
|
||||||
}
|
|
||||||
|
|
||||||
impl HasArg : Eq {
|
|
||||||
pure fn eq(&self, other: &HasArg) -> bool {
|
|
||||||
((*self) as uint) == ((*other) as uint)
|
|
||||||
}
|
|
||||||
pure fn ne(&self, other: &HasArg) -> bool { !(*self).eq(other) }
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Opt : Eq {
|
|
||||||
pure fn eq(&self, other: &Opt) -> bool {
|
|
||||||
(*self).name == (*other).name &&
|
|
||||||
(*self).hasarg == (*other).hasarg &&
|
|
||||||
(*self).occur == (*other).occur
|
|
||||||
}
|
|
||||||
pure fn ne(&self, other: &Opt) -> bool { !(*self).eq(other) }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create an option that is required and takes an argument
|
/// Create an option that is required and takes an argument
|
||||||
pub fn reqopt(name: &str) -> Opt {
|
pub fn reqopt(name: &str) -> Opt {
|
||||||
return Opt {name: mkname(name), hasarg: Yes, occur: Req};
|
return Opt {name: mkname(name), hasarg: Yes, occur: Req};
|
||||||
|
@ -178,39 +139,20 @@ pub fn optmulti(name: &str) -> Opt {
|
||||||
return Opt {name: mkname(name), hasarg: Yes, occur: Multi};
|
return Opt {name: mkname(name), hasarg: Yes, occur: Multi};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[deriving_eq]
|
||||||
enum Optval { Val(~str), Given, }
|
enum Optval { Val(~str), Given, }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The result of checking command line arguments. Contains a vector
|
* The result of checking command line arguments. Contains a vector
|
||||||
* of matches and a vector of free strings.
|
* of matches and a vector of free strings.
|
||||||
*/
|
*/
|
||||||
|
#[deriving_eq]
|
||||||
pub struct Matches {
|
pub struct Matches {
|
||||||
opts: ~[Opt],
|
opts: ~[Opt],
|
||||||
vals: ~[~[Optval]],
|
vals: ~[~[Optval]],
|
||||||
free: ~[~str]
|
free: ~[~str]
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Optval : Eq {
|
|
||||||
pure fn eq(&self, other: &Optval) -> bool {
|
|
||||||
match (*self) {
|
|
||||||
Val(ref s) => match *other { Val (ref os) => s == os,
|
|
||||||
Given => false },
|
|
||||||
Given => match *other { Val(_) => false,
|
|
||||||
Given => true }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pure fn ne(&self, other: &Optval) -> bool { !(*self).eq(other) }
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Matches : Eq {
|
|
||||||
pure fn eq(&self, other: &Matches) -> bool {
|
|
||||||
(*self).opts == (*other).opts &&
|
|
||||||
(*self).vals == (*other).vals &&
|
|
||||||
(*self).free == (*other).free
|
|
||||||
}
|
|
||||||
pure fn ne(&self, other: &Matches) -> bool { !(*self).eq(other) }
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_arg(arg: &str) -> bool {
|
fn is_arg(arg: &str) -> bool {
|
||||||
return arg.len() > 1 && arg[0] == '-' as u8;
|
return arg.len() > 1 && arg[0] == '-' as u8;
|
||||||
}
|
}
|
||||||
|
@ -230,6 +172,7 @@ fn find_opt(opts: &[Opt], nm: Name) -> Option<uint> {
|
||||||
* The type returned when the command line does not conform to the
|
* The type returned when the command line does not conform to the
|
||||||
* expected format. Pass this value to <fail_str> to get an error message.
|
* expected format. Pass this value to <fail_str> to get an error message.
|
||||||
*/
|
*/
|
||||||
|
#[deriving_eq]
|
||||||
pub enum Fail_ {
|
pub enum Fail_ {
|
||||||
ArgumentMissing(~str),
|
ArgumentMissing(~str),
|
||||||
UnrecognizedOption(~str),
|
UnrecognizedOption(~str),
|
||||||
|
@ -238,35 +181,6 @@ pub enum Fail_ {
|
||||||
UnexpectedArgument(~str),
|
UnexpectedArgument(~str),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Fail_ : Eq {
|
|
||||||
// this whole thing should be easy to infer...
|
|
||||||
pure fn eq(&self, other: &Fail_) -> bool {
|
|
||||||
match (*self) {
|
|
||||||
ArgumentMissing(ref s) => {
|
|
||||||
match *other { ArgumentMissing(ref so) => s == so,
|
|
||||||
_ => false }
|
|
||||||
}
|
|
||||||
UnrecognizedOption(ref s) => {
|
|
||||||
match *other { UnrecognizedOption(ref so) => s == so,
|
|
||||||
_ => false }
|
|
||||||
}
|
|
||||||
OptionMissing(ref s) => {
|
|
||||||
match *other { OptionMissing(ref so) => s == so,
|
|
||||||
_ => false }
|
|
||||||
}
|
|
||||||
OptionDuplicated(ref s) => {
|
|
||||||
match *other { OptionDuplicated(ref so) => s == so,
|
|
||||||
_ => false }
|
|
||||||
}
|
|
||||||
UnexpectedArgument(ref s) => {
|
|
||||||
match *other { UnexpectedArgument(ref so) => s == so,
|
|
||||||
_ => false }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pure fn ne(&self, other: &Fail_) -> bool { !(*self).eq(other) }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Convert a `fail_` enum into an error string
|
/// Convert a `fail_` enum into an error string
|
||||||
pub fn fail_str(f: Fail_) -> ~str {
|
pub fn fail_str(f: Fail_) -> ~str {
|
||||||
return match f {
|
return match f {
|
||||||
|
@ -523,6 +437,7 @@ pub fn opt_default(mm: &Matches, nm: &str, def: &str) -> Option<~str> {
|
||||||
_ => Some::<~str>(str::from_slice(def)) }
|
_ => Some::<~str>(str::from_slice(def)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[deriving_eq]
|
||||||
enum FailType {
|
enum FailType {
|
||||||
ArgumentMissing_,
|
ArgumentMissing_,
|
||||||
UnrecognizedOption_,
|
UnrecognizedOption_,
|
||||||
|
@ -531,13 +446,6 @@ enum FailType {
|
||||||
UnexpectedArgument_,
|
UnexpectedArgument_,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FailType : Eq {
|
|
||||||
pure fn eq(&self, other: &FailType) -> bool {
|
|
||||||
((*self) as uint) == ((*other) as uint)
|
|
||||||
}
|
|
||||||
pure fn ne(&self, other: &FailType) -> bool { !(*self).eq(other) }
|
|
||||||
}
|
|
||||||
|
|
||||||
/** A module which provides a way to specify descriptions and
|
/** A module which provides a way to specify descriptions and
|
||||||
* groups of short and long option names, together.
|
* groups of short and long option names, together.
|
||||||
*/
|
*/
|
||||||
|
@ -546,6 +454,7 @@ pub mod groups {
|
||||||
/** one group of options, e.g., both -h and --help, along with
|
/** one group of options, e.g., both -h and --help, along with
|
||||||
* their shared description and properties
|
* their shared description and properties
|
||||||
*/
|
*/
|
||||||
|
#[deriving_eq]
|
||||||
pub struct OptGroup {
|
pub struct OptGroup {
|
||||||
short_name: ~str,
|
short_name: ~str,
|
||||||
long_name: ~str,
|
long_name: ~str,
|
||||||
|
@ -555,20 +464,6 @@ pub mod groups {
|
||||||
occur: Occur
|
occur: Occur
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OptGroup : Eq {
|
|
||||||
pure fn eq(&self, other: &OptGroup) -> bool {
|
|
||||||
(*self).short_name == (*other).short_name &&
|
|
||||||
(*self).long_name == (*other).long_name &&
|
|
||||||
(*self).hint == (*other).hint &&
|
|
||||||
(*self).desc == (*other).desc &&
|
|
||||||
(*self).hasarg == (*other).hasarg &&
|
|
||||||
(*self).occur == (*other).occur
|
|
||||||
}
|
|
||||||
pure fn ne(&self, other: &OptGroup) -> bool {
|
|
||||||
!self.eq(other)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a long option that is required and takes an argument
|
/// Create a long option that is required and takes an argument
|
||||||
pub fn reqopt(short_name: &str, long_name: &str,
|
pub fn reqopt(short_name: &str, long_name: &str,
|
||||||
desc: &str, hint: &str) -> OptGroup {
|
desc: &str, hint: &str) -> OptGroup {
|
||||||
|
@ -733,7 +628,7 @@ mod tests {
|
||||||
#[legacy_exports];
|
#[legacy_exports];
|
||||||
use opt = getopts;
|
use opt = getopts;
|
||||||
use result::{Err, Ok};
|
use result::{Err, Ok};
|
||||||
use opt::groups::OptGroup;
|
use getopts::groups::OptGroup;
|
||||||
|
|
||||||
fn check_fail_type(f: Fail_, ft: FailType) {
|
fn check_fail_type(f: Fail_, ft: FailType) {
|
||||||
match f {
|
match f {
|
||||||
|
|
|
@ -16,6 +16,7 @@ use core::option;
|
||||||
use option::*;
|
use option::*;
|
||||||
use option::{Some, None};
|
use option::{Some, None};
|
||||||
|
|
||||||
|
#[deriving_eq]
|
||||||
pub enum List<T> {
|
pub enum List<T> {
|
||||||
Cons(T, @List<T>),
|
Cons(T, @List<T>),
|
||||||
Nil,
|
Nil,
|
||||||
|
@ -157,26 +158,6 @@ pub fn each<T>(l: @List<T>, f: fn(&T) -> bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T:Eq> List<T> : Eq {
|
|
||||||
pure fn eq(&self, other: &List<T>) -> bool {
|
|
||||||
match (*self) {
|
|
||||||
Cons(ref e0a, e1a) => {
|
|
||||||
match (*other) {
|
|
||||||
Cons(ref e0b, e1b) => e0a == e0b && e1a == e1b,
|
|
||||||
_ => false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Nil => {
|
|
||||||
match (*other) {
|
|
||||||
Nil => true,
|
|
||||||
_ => false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pure fn ne(&self, other: &List<T>) -> bool { !(*self).eq(other) }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#[legacy_exports];
|
#[legacy_exports];
|
||||||
|
|
|
@ -92,15 +92,9 @@ fn parse_opts(args: &[~str]) -> OptRes {
|
||||||
return either::Left(test_opts);
|
return either::Left(test_opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[deriving_eq]
|
||||||
pub enum TestResult { TrOk, TrFailed, TrIgnored, }
|
pub enum TestResult { TrOk, TrFailed, TrIgnored, }
|
||||||
|
|
||||||
impl TestResult : Eq {
|
|
||||||
pure fn eq(&self, other: &TestResult) -> bool {
|
|
||||||
((*self) as uint) == ((*other) as uint)
|
|
||||||
}
|
|
||||||
pure fn ne(&self, other: &TestResult) -> bool { !(*self).eq(other) }
|
|
||||||
}
|
|
||||||
|
|
||||||
type ConsoleTestState =
|
type ConsoleTestState =
|
||||||
@{out: io::Writer,
|
@{out: io::Writer,
|
||||||
log_out: Option<io::Writer>,
|
log_out: Option<io::Writer>,
|
||||||
|
|
|
@ -79,6 +79,7 @@ use serialization::{Serializer,Serializable,
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#[deriving_eq]
|
||||||
struct WorkKey {
|
struct WorkKey {
|
||||||
kind: ~str,
|
kind: ~str,
|
||||||
name: ~str
|
name: ~str
|
||||||
|
@ -100,15 +101,6 @@ impl WorkKey {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WorkKey: core::cmp::Eq {
|
|
||||||
pure fn eq(&self, other: &WorkKey) -> bool {
|
|
||||||
self.kind == other.kind && self.name == other.name
|
|
||||||
}
|
|
||||||
pure fn ne(&self, other: &WorkKey) -> bool {
|
|
||||||
self.kind != other.kind || self.name != other.name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type WorkMap = LinearMap<WorkKey, ~str>;
|
type WorkMap = LinearMap<WorkKey, ~str>;
|
||||||
|
|
||||||
struct Database {
|
struct Database {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue