You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's September 22, and I just download today's compiler using rustup.sh. I tried to compile this modified version of rust-replace-map, using FnOnce:
#![feature(unboxed_closures, overloaded_calls)]//! Exposes `replace_map`, for replacing values at mutable memory locations.use std::ptr;/// Replace the value at a mutable memory location with the value/// produced by the passed in closure.////// Does not create an intermediate value, so is more efficient and/// ergonomic in cases where producing a value to pass to mem::replace/// is hard.pubfnreplace_map<'a,T,F>(src:&mutT,prod:F)whereF:FnOnce(T) -> T{// Read the value, pass it to prod, then write-over src.//// Safe because the value originally behind src is dropped// inside of prod and is then immediately written over.unsafe{*src = prod(ptr::read(src as*mutTas*constT));}}#[test]fntest_works(){letmut a = 7u;let b = &mut a;replace_map(b, |:x:uint| x *2);assert_eq!(*b,14u);}
It's September 22, and I just download today's compiler using
rustup.sh
. I tried to compile this modified version of rust-replace-map, usingFnOnce
:…and got:
The text was updated successfully, but these errors were encountered: