Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make Option's iter method use a lifetime #4874

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ pub pure fn map_default<T, U>(opt: &r/Option<T>, def: U,
}

#[inline(always)]
pub pure fn iter<T>(opt: &Option<T>, f: fn(x: &T)) {
pub pure fn iter<T>(opt: &r/Option<T>, f: fn(x: &r/T)) {
//! Performs an operation on the contained value by reference
match *opt { None => (), Some(ref t) => f(t) }
}
Expand Down Expand Up @@ -313,7 +313,7 @@ impl<T> Option<T> {

/// Performs an operation on the contained value by reference
#[inline(always)]
pure fn iter(&self, f: fn(x: &T)) { iter(self, f) }
pure fn iter(&self, f: fn(x: &self/T)) { iter(self, f) }

/**
Gets an immutable reference to the value inside an option.
Expand Down
8 changes: 4 additions & 4 deletions src/libstd/treemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,18 +561,18 @@ impl <K: Ord, V> TreeNode<K, V> {

pure fn each<K: Ord, V>(node: &r/Option<~TreeNode<K, V>>,
f: fn(&(&r/K, &r/V)) -> bool) {
do node.map |x| {
do node.iter |x| {
each(&x.left, f);
if f(&(&x.key, &x.value)) { each(&x.right, f) }
};
}
}

pure fn each_reverse<K: Ord, V>(node: &r/Option<~TreeNode<K, V>>,
f: fn(&(&r/K, &r/V)) -> bool) {
do node.map |x| {
do node.iter |x| {
each_reverse(&x.right, f);
if f(&(&x.key, &x.value)) { each_reverse(&x.left, f) }
};
}
}

// Remove left horizontal link by rotating right
Expand Down