pub enum TempStack<Root: TempRepr, Frame: TempRepr> {
Root {
data: Root,
},
Frame {
data: Frame,
parent: TempRefPin<TempStack<Root, Frame>>,
},
}
Expand description
A linked list consisting of a single item of type Root
and arbitrarily many items of type
Frame
. Both types must implement temp_inst::TempRepr
, which declares them as “temporary
representations” of possibly lifetime-dependent types such as references.
A TempStack
can be constructed and referenced in a mutable or shared fashion, and in the
mutable case the usual exclusivity rules apply. However, adding an item never alters the list
it was added to; it merely creates a new list that borrows the original one (exclusively or
shared).
§Remarks
Although the root and frames can consist of arbitrary data via temp_inst::SelfRepr
, usually
the size of both should be kept small, using references via temp_inst::TempRef
or
temp_inst::TempRefMut
instead, for two reasons.
- Both root and frame data are stored in the same
enum
, so a large root also enlarges each frame. - The iterators return copies/clones of the frame data. Therefore, if frames are large, iteration should be implemented manually.
Variants§
Implementations§
Source§impl<Root: TempRepr, Frame: TempRepr> TempStack<Root, Frame>
impl<Root: TempRepr, Frame: TempRepr> TempStack<Root, Frame>
Sourcepub fn new_root(data: Root::Shared<'_>) -> TempStackFrame<'_, Root, Frame>
pub fn new_root(data: Root::Shared<'_>) -> TempStackFrame<'_, Root, Frame>
Creates a new stack and returns a TempInst
object that only hands out shared references.
Sourcepub fn new_frame<'a>(
&'a self,
data: Frame::Shared<'a>,
) -> TempStackFrame<'a, Root, Frame>
pub fn new_frame<'a>( &'a self, data: Frame::Shared<'a>, ) -> TempStackFrame<'a, Root, Frame>
Creates a new stack that extends self
with the given frame, and returns a TempInst
object that only hands out shared references.
Sourcepub fn iter(&self) -> TempStackIter<'_, Root, Frame> ⓘ
pub fn iter(&self) -> TempStackIter<'_, Root, Frame> ⓘ
Returns an iterator that traverses the stack starting at the current frame and ending at the root.
The iterator returns the data of each frame, and also provides TempStackIter::into_root
to access the root data.
Source§impl<Root: TempReprMut, Frame: TempReprMut> TempStack<Root, Frame>
impl<Root: TempReprMut, Frame: TempReprMut> TempStack<Root, Frame>
Sourcepub fn new_root_mut(
data: Root::Mutable<'_>,
) -> TempStackFrameMut<'_, Root, Frame>
pub fn new_root_mut( data: Root::Mutable<'_>, ) -> TempStackFrameMut<'_, Root, Frame>
Creates a new stack and returns a TempInstPin
object that can hand out pinned mutable
references.
Note that this requires the resulting object to be pinned, e.g. using core::pin::pin!
.
Sourcepub fn new_frame_mut<'a>(
self: Pin<&'a mut Self>,
data: Frame::Mutable<'a>,
) -> TempStackFrameMut<'a, Root, Frame>
pub fn new_frame_mut<'a>( self: Pin<&'a mut Self>, data: Frame::Mutable<'a>, ) -> TempStackFrameMut<'a, Root, Frame>
Creates a new stack that extends self
with the given frame, and returns a TempInstPin
object that can hand out pinned mutable references.
Note that this requires the resulting object to be pinned, e.g. using core::pin::pin!
.
Sourcepub fn iter_mut(self: Pin<&mut Self>) -> TempStackIterMut<'_, Root, Frame> ⓘ
pub fn iter_mut(self: Pin<&mut Self>) -> TempStackIterMut<'_, Root, Frame> ⓘ
Returns an iterator that traverses the stack starting at the current frame and ending at the root, returning mutable frames.
The iterator returns the data of each frame, and also provides
TempStackIterMut::into_root
to access the root data.
Trait Implementations§
Source§impl<Root: TempRepr, Frame: TempRepr> TempRepr for TempStack<Root, Frame>
impl<Root: TempRepr, Frame: TempRepr> TempRepr for TempStack<Root, Frame>
Source§impl<Root: TempReprMut, Frame: TempReprMut> TempReprMut for TempStack<Root, Frame>
impl<Root: TempReprMut, Frame: TempReprMut> TempReprMut for TempStack<Root, Frame>
Source§type Mutable<'a> = Either<<Root as TempReprMut>::Mutable<'a>, (<Frame as TempReprMut>::Mutable<'a>, <TempRefPin<TempStack<Root, Frame>> as TempReprMut>::Mutable<'a>)>
where
Self: 'a
type Mutable<'a> = Either<<Root as TempReprMut>::Mutable<'a>, (<Frame as TempReprMut>::Mutable<'a>, <TempRefPin<TempStack<Root, Frame>> as TempReprMut>::Mutable<'a>)> where Self: 'a
Self
is a temporary representation of. May contain mutable references of
lifetime 'a
.Source§unsafe fn new_temp_mut(obj: Self::Mutable<'_>) -> Self
unsafe fn new_temp_mut(obj: Self::Mutable<'_>) -> Self
Source§fn get_mut(&mut self) -> Self::Mutable<'_>
fn get_mut(&mut self) -> Self::Mutable<'_>
Source§fn get_mut_pinned(self: Pin<&mut Self>) -> Self::Mutable<'_>
fn get_mut_pinned(self: Pin<&mut Self>) -> Self::Mutable<'_>
TempReprMut::get_mut
, but takes a pinned mutable reference to Self
.Auto Trait Implementations§
impl<Root, Frame> Freeze for TempStack<Root, Frame>
impl<Root, Frame> RefUnwindSafe for TempStack<Root, Frame>where
Root: RefUnwindSafe,
Frame: RefUnwindSafe,
impl<Root, Frame> Send for TempStack<Root, Frame>
impl<Root, Frame> Sync for TempStack<Root, Frame>
impl<Root, Frame> Unpin for TempStack<Root, Frame>
impl<Root, Frame> UnwindSafe for TempStack<Root, Frame>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more