@ -1,8 +1,7 @@
//! Single-index references.
//! Single-index references.
use super ::* ;
use super ::* ;
use std ::sync ::Arc ;
#[ derive(Debug) ] // PartialEq, PartialOrd
#[ derive(Debug) ] // PartialEq, PartialOrd ///XXX: TODO: Should this be Clone (and maybe even Copy)? Check OwnedRef below...
pub struct Ref < ' re , ' a , T : ' a >
pub struct Ref < ' re , ' a , T : ' a >
{
{
pub ( super ) pop : & ' re Populator < ' a , T > ,
pub ( super ) pop : & ' re Populator < ' a , T > ,
@ -11,7 +10,7 @@ pub struct Ref<'re, 'a, T: 'a>
//TODO: OR: Hold a reference to the actual AtomicBool at `idx` itself?
//TODO: OR: Hold a reference to the actual AtomicBool at `idx` itself?
}
}
#[ derive(Debug )]
#[ derive(Debug , Clone )] // PartialEq, PartialOrd //XXX: TODO: Should this actually be `Clone`? Ref isn't, because its supposed to be a single reference. But since this is arc'd?
pub struct OwnedRef < ' a , T : ' a > // PartialEq, PartialOrd
pub struct OwnedRef < ' a , T : ' a > // PartialEq, PartialOrd
{
{
pub ( super ) pop : Arc < Populator < ' a , T > > ,
pub ( super ) pop : Arc < Populator < ' a , T > > ,
@ -63,6 +62,12 @@ impl<'re, 'a, T: 'a> PartialOrd for Ref<'re, 'a, T>
impl < ' re , ' a , T : ' a > Ref < ' re , ' a , T >
impl < ' re , ' a , T : ' a > Ref < ' re , ' a , T >
{
{
/// Get a reference to the parent populator
#[ inline ]
pub fn parent ( & self ) -> & Populator < ' a , T >
{
& self . pop
}
/// The index that this `Ref` refers to.
/// The index that this `Ref` refers to.
#[ inline ]
#[ inline ]
pub fn slot ( & self ) -> usize
pub fn slot ( & self ) -> usize
@ -92,10 +97,30 @@ impl<'re, 'a, T: 'a> Ref<'re, 'a, T>
{
{
self . pop . insert ( self . idx , value )
self . pop . insert ( self . idx , value )
}
}
/// Consume into the inner populator reference and slot index
#[ inline ]
pub fn into_parts ( self ) -> ( & ' re Populator < ' a , T > , usize )
{
( self . pop , self . idx )
}
/// Consume into the inner populator reference
#[ inline ]
pub fn into_inner ( self ) -> & ' re Populator < ' a , T >
{
self . pop
}
}
}
impl < ' a , T :' a > OwnedRef < ' a , T >
impl < ' a , T :' a > OwnedRef < ' a , T >
{
{
/// Get a reference to the parent `Arc`.
#[ inline ]
pub fn parent ( & self ) -> & Arc < Populator < ' a , T > >
{
& self . pop
}
/// The index that this `Ref` refers to.
/// The index that this `Ref` refers to.
#[ inline ]
#[ inline ]
pub fn slot ( & self ) -> usize
pub fn slot ( & self ) -> usize
@ -126,6 +151,13 @@ impl<'a, T:'a> OwnedRef<'a, T>
self . pop . insert ( self . idx , value )
self . pop . insert ( self . idx , value )
}
}
/// Consume into the inner populator and slot index
#[ inline ]
pub fn into_parts ( self ) -> ( Arc < Populator < ' a , T > > , usize )
{
( self . pop , self . idx )
}
/// Consume into the inner populator
/// Consume into the inner populator
#[ inline ]
#[ inline ]
pub fn into_inner ( self ) -> Arc < Populator < ' a , T > >
pub fn into_inner ( self ) -> Arc < Populator < ' a , T > >