Skip to content
This repository has been archived by the owner on Apr 12, 2019. It is now read-only.

Commit

Permalink
Explicit self parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
uasi committed Apr 4, 2013
1 parent a1b41af commit 2bc6231
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions test-pcre.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,42 @@ use pcre::*;
#[cfg(test)]
mod test_util {
pub trait OptionUtil<T> {
fn is_some_and(blk: &fn(T) -> bool) -> bool;
fn is_none_and(blk: &fn() -> bool) -> bool;
fn is_some_and(&self, blk: &fn(T) -> bool) -> bool;
fn is_none_and(&self, blk: &fn() -> bool) -> bool;
}

impl<T: Copy> OptionUtil<T> for Option<T> {
fn is_some_and(blk: &fn(T) -> bool) -> bool {
match self {
fn is_some_and(&self, blk: &fn(T) -> bool) -> bool {
match *self {
Some(t) => blk(t),
None => false,
}
}

// Who wants?
fn is_none_and(blk: &fn() -> bool) -> bool {
match self {
fn is_none_and(&self, blk: &fn() -> bool) -> bool {
match *self {
Some(_) => false,
None => blk(),
}
}
}

pub trait ResultUtil<T, U> {
fn is_ok_and(blk: &fn(T) -> bool) -> bool;
fn is_err_and(blk: &fn(U) -> bool) -> bool;
fn is_ok_and(&self, blk: &fn(T) -> bool) -> bool;
fn is_err_and(&self, blk: &fn(U) -> bool) -> bool;
}

impl<T: Copy, U: Copy> ResultUtil<T, U> for Result<T, U> {
fn is_ok_and(blk: &fn(T) -> bool) -> bool {
match self {
fn is_ok_and(&self, blk: &fn(T) -> bool) -> bool {
match *self {
Ok(t) => blk(t),
Err(_) => false,
}
}

fn is_err_and(blk: &fn(U) -> bool) -> bool {
match self {
fn is_err_and(&self, blk: &fn(U) -> bool) -> bool {
match *self {
Ok(_) => false,
Err(u) => blk(u),
}
Expand Down

0 comments on commit 2bc6231

Please sign in to comment.