Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upTracking issue for `cell_extras` stabilization #27746
Comments
aturon
added
T-libs
B-unstable
labels
Aug 12, 2015
This comment has been minimized.
This comment has been minimized.
|
cc @SimonSapin |
This comment has been minimized.
This comment has been minimized.
|
This is the kind of thing (unlike say |
This comment has been minimized.
This comment has been minimized.
|
(Ok, thinking a bit more about it, this may not be true. Something like https://github.com/Kimundi/owning-ref-rs/ could, using |
This comment has been minimized.
This comment has been minimized.
mbrt
commented
Dec 8, 2015
|
What about making |
This comment has been minimized.
This comment has been minimized.
|
I’d like to nominate at least
fn borrow_get<'a>(hashmap: &'a RefCell<HashMap<String, String>>, key: &str)
-> Option<Ref<'a String>> {
let hashmap: = hashmap.borrow();
if hashmap:.contains_key(key) { // Duplicated hash table lookup.
Some(Ref::map(|hashmap| {
hashmap[key] // panic!() for missing key unlikely to be optimized away
}))
} else {
None
}
}It’s probably possible to do it unsafely without the run-time cost with raw pointers. (But still less risky than guessing the memory layout of |
aturon
added
the
I-nominated
label
Jan 19, 2016
This comment has been minimized.
This comment has been minimized.
|
For future reference, here is fully generic use std::cell::{Ref, RefMut};
pub fn ref_filter_map<
T: ?Sized,
U: ?Sized,
F: FnOnce(&T) -> Option<&U>
>(orig: Ref<T>, f: F) -> Option<Ref<U>> {
f(&orig)
.map(|new| new as *const U)
.map(|raw| Ref::map(orig, |_| unsafe { &*raw }))
}
pub fn ref_mut_filter_map<
T: ?Sized,
U: ?Sized,
F: FnOnce(&mut T) -> Option<&mut U>
>(mut orig: RefMut<T>, f: F) -> Option<RefMut<U>> {
f(&mut orig)
.map(|new| new as *mut U)
.map(|raw| RefMut::map(orig, |_| unsafe { &mut *raw }))
} |
This comment has been minimized.
This comment has been minimized.
|
We're specifically considering stabilizing |
alexcrichton
added
final-comment-period
and removed
I-nominated
labels
Jan 29, 2016
alexcrichton
referenced this issue
Jan 29, 2016
Merged
Add RwLockReadGuard::map for transforming guards to contain sub-borrows. #30834
This comment has been minimized.
This comment has been minimized.
|
As just noted in #30834: I've discovered a safety hole in This is not a problem with the It would be possible to provide a similar, but safe, API by defining a separate type for "mapped" mutex guards that can't be used with a |
reem
added a commit
to reem/rust
that referenced
this issue
Feb 5, 2016
reem
referenced this issue
Feb 5, 2016
Merged
Remove MutexGuard::map, as it is not safe in combination with Condvar. #31428
This comment has been minimized.
This comment has been minimized.
|
With |
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton Certainly we shouldn't stabilize them, and I tend to agree that we should probably remove them and do this in a more considered way. |
This comment has been minimized.
This comment has been minimized.
|
If you decide to keep these functions (or at least the one on RwLock I guess), the lifetimes should be removed from the closure like in http://is.gd/vUbM4D (the example in the link above modified for RwLock currently results in use-after-free). |
This comment has been minimized.
This comment has been minimized.
|
I need a I went ahead and also demoed a (I believe) safe API for Code: https://github.com/reem/rust-shared-mutex EDIT: Also submitted #31440 to fix the safety hole noted by @whataloadofwhat and update the |
bors
added a commit
that referenced
this issue
Feb 6, 2016
This comment has been minimized.
This comment has been minimized.
|
The libs team discussed this during triage yesterday and the decision was to:
|
alexcrichton
added a commit
to alexcrichton/rust
that referenced
this issue
Feb 26, 2016
alexcrichton
added a commit
to alexcrichton/rust
that referenced
this issue
Feb 26, 2016
alexcrichton
referenced this issue
Feb 26, 2016
Merged
std: Stabilize APIs for the 1.8 release #31928
alexcrichton
added a commit
to alexcrichton/rust
that referenced
this issue
Feb 27, 2016
Manishearth
added a commit
to Manishearth/rust
that referenced
this issue
Feb 27, 2016
bors
added a commit
that referenced
this issue
Feb 27, 2016
alexcrichton
added a commit
to alexcrichton/rust
that referenced
this issue
Feb 28, 2016
alexcrichton
added a commit
to alexcrichton/rust
that referenced
this issue
Feb 28, 2016
bors
added a commit
that referenced
this issue
Feb 28, 2016
alexcrichton
added a commit
to alexcrichton/rust
that referenced
this issue
Feb 28, 2016
bors
added a commit
that referenced
this issue
Feb 28, 2016
alexcrichton
added a commit
to alexcrichton/rust
that referenced
this issue
Feb 29, 2016
bors
added a commit
that referenced
this issue
Feb 29, 2016
bors
closed this
in
#31928
Feb 29, 2016
This comment has been minimized.
This comment has been minimized.
|
Reopening as apparently |
alexcrichton
reopened this
May 26, 2016
This comment has been minimized.
This comment has been minimized.
|
Also cc #33880, possible unsoundness with that method. |
alexcrichton
removed
the
final-comment-period
label
Jun 9, 2016
This comment has been minimized.
This comment has been minimized.
|
@rfcbot fcp merge Sounds like |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Nov 1, 2016
•
|
Team member @alexcrichton has proposed to merge this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Nov 12, 2016
|
psst @alexcrichton, I wasn't able to add the |
alexcrichton
added
the
final-comment-period
label
Nov 12, 2016
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Nov 22, 2016
|
The final comment period is now complete. |
aturon commentedAug 12, 2015
The
Reftype connected toRefCellsupports some methods for changing the type of the reference, such asmapandfilter_map. Whilemapis clearly fully general,filter_mapis somewhat of a special case hooked intoOption. To make it fully general would likely require HKT. We need an overall plan before stabilization.