Skip to content

Option mutate returns bool #8211

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

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/librustc/middle/trans/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1155,11 +1155,11 @@ fn store_non_ref_bindings(bcx: @mut Block,
let datum = Datum {val: llval, ty: binding_info.ty,
mode: ByRef(ZeroMem)};
bcx = datum.store_to(bcx, INIT, lldest);
do opt_temp_cleanups.mutate |temp_cleanups| {
opt_temp_cleanups.mutate(|temp_cleanups| {
add_clean_temp_mem(bcx, lldest, binding_info.ty);
temp_cleanups.push(lldest);
temp_cleanups
}
});
}
TrByRef => {}
}
Expand Down
14 changes: 10 additions & 4 deletions src/libstd/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,19 +237,25 @@ impl<T> Option<T> {
self.take().map_consume_default(def, blk)
}

/// Apply a function to the contained value or do nothing
pub fn mutate(&mut self, f: &fn(T) -> T) {
/// Apply a function to the contained value and return true, or return false
pub fn mutate(&mut self, f: &fn(T) -> T) -> bool {
if self.is_some() {
*self = Some(f(self.take_unwrap()));
return true;
} else {
return false;
}
}

/// Apply a function to the contained value or set it to a default
pub fn mutate_default(&mut self, def: T, f: &fn(T) -> T) {
/// Apply a function to the contained value and return true,
/// or set it to a default and return false
pub fn mutate_default(&mut self, def: T, f: &fn(T) -> T) -> bool {
if self.is_some() {
*self = Some(f(self.take_unwrap()));
return true;
} else {
*self = Some(def);
return false;
}
}

Expand Down