Fallout: btree. Rephrase invariant lifetime in terms of PhantomData.
This commit is contained in:
parent
c5579ca340
commit
b3c00a69f2
1 changed files with 13 additions and 4 deletions
|
@ -512,13 +512,22 @@ mod stack {
|
||||||
use super::super::node::handle;
|
use super::super::node::handle;
|
||||||
use vec::Vec;
|
use vec::Vec;
|
||||||
|
|
||||||
|
struct InvariantLifetime<'id>(
|
||||||
|
marker::PhantomData<::core::cell::Cell<&'id ()>>);
|
||||||
|
|
||||||
|
impl<'id> InvariantLifetime<'id> {
|
||||||
|
fn new() -> InvariantLifetime<'id> {
|
||||||
|
InvariantLifetime(marker::PhantomData)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A generic mutable reference, identical to `&mut` except for the fact that its lifetime
|
/// A generic mutable reference, identical to `&mut` except for the fact that its lifetime
|
||||||
/// parameter is invariant. This means that wherever an `IdRef` is expected, only an `IdRef`
|
/// parameter is invariant. This means that wherever an `IdRef` is expected, only an `IdRef`
|
||||||
/// with the exact requested lifetime can be used. This is in contrast to normal references,
|
/// with the exact requested lifetime can be used. This is in contrast to normal references,
|
||||||
/// where `&'static` can be used in any function expecting any lifetime reference.
|
/// where `&'static` can be used in any function expecting any lifetime reference.
|
||||||
pub struct IdRef<'id, T: 'id> {
|
pub struct IdRef<'id, T: 'id> {
|
||||||
inner: &'id mut T,
|
inner: &'id mut T,
|
||||||
marker: marker::InvariantLifetime<'id>
|
_marker: InvariantLifetime<'id>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'id, T> Deref for IdRef<'id, T> {
|
impl<'id, T> Deref for IdRef<'id, T> {
|
||||||
|
@ -560,7 +569,7 @@ mod stack {
|
||||||
pub struct Pusher<'id, 'a, K:'a, V:'a> {
|
pub struct Pusher<'id, 'a, K:'a, V:'a> {
|
||||||
map: &'a mut BTreeMap<K, V>,
|
map: &'a mut BTreeMap<K, V>,
|
||||||
stack: Stack<K, V>,
|
stack: Stack<K, V>,
|
||||||
marker: marker::InvariantLifetime<'id>
|
_marker: InvariantLifetime<'id>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, K, V> PartialSearchStack<'a, K, V> {
|
impl<'a, K, V> PartialSearchStack<'a, K, V> {
|
||||||
|
@ -595,11 +604,11 @@ mod stack {
|
||||||
let pusher = Pusher {
|
let pusher = Pusher {
|
||||||
map: self.map,
|
map: self.map,
|
||||||
stack: self.stack,
|
stack: self.stack,
|
||||||
marker: marker::InvariantLifetime
|
_marker: InvariantLifetime::new(),
|
||||||
};
|
};
|
||||||
let node = IdRef {
|
let node = IdRef {
|
||||||
inner: unsafe { &mut *self.next },
|
inner: unsafe { &mut *self.next },
|
||||||
marker: marker::InvariantLifetime
|
_marker: InvariantLifetime::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
closure(pusher, node)
|
closure(pusher, node)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue