Enum TempStack

Source
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§

§

Root

Fields

§data: Root
§

Frame

Fields

§data: Frame
§parent: TempRefPin<TempStack<Root, Frame>>

Implementations§

Source§

impl<Root: TempRepr, Frame: TempRepr> TempStack<Root, Frame>

Source

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.

Source

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.

Source

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>

Source

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!.

Source

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!.

Source

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 + Debug, Frame: TempRepr + Debug> Debug for TempStack<Root, Frame>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Root: TempRepr, Frame: TempRepr> TempRepr for TempStack<Root, Frame>

Source§

type Shared<'a> = Either<<Root as TempRepr>::Shared<'a>, (<Frame as TempRepr>::Shared<'a>, <TempRefPin<TempStack<Root, Frame>> as TempRepr>::Shared<'a>)> where Self: 'a

The type that Self is a temporary representation of. May contain shared references of lifetime 'a.
Source§

unsafe fn new_temp(obj: Self::Shared<'_>) -> Self

Converts the given object to its temporary representation. Read more
Source§

fn get(&self) -> Self::Shared<'_>

Converts from a shared temporary reference back to the original type with a suitably-restricted lifetime.
Source§

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

The type that Self is a temporary representation of. May contain mutable references of lifetime 'a.
Source§

unsafe fn new_temp_mut(obj: Self::Mutable<'_>) -> Self

Converts the given object to a temporary representation without a lifetime parameter. Read more
Source§

fn get_mut(&mut self) -> Self::Mutable<'_>

Converts from a mutable reference to the temporary representation back to the original type, with a restricted lifetime.
Source§

fn get_mut_pinned(self: Pin<&mut Self>) -> Self::Mutable<'_>

Like TempReprMut::get_mut, but takes a pinned mutable reference to Self.

Auto Trait Implementations§

§

impl<Root, Frame> Freeze for TempStack<Root, Frame>
where Root: Freeze, Frame: Freeze,

§

impl<Root, Frame> RefUnwindSafe for TempStack<Root, Frame>
where Root: RefUnwindSafe, Frame: RefUnwindSafe,

§

impl<Root, Frame> Send for TempStack<Root, Frame>
where Root: Send, Frame: Send,

§

impl<Root, Frame> Sync for TempStack<Root, Frame>
where Root: Sync, Frame: Sync,

§

impl<Root, Frame> Unpin for TempStack<Root, Frame>
where Root: Unpin, Frame: Unpin,

§

impl<Root, Frame> UnwindSafe for TempStack<Root, Frame>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.