Struct froggy::WeakPointer [] [src]

pub struct WeakPointer<T> { /* fields omitted */ }

Weak variant of Pointer. WeakPointers are used to avoid deadlocking when dropping structures with cycled references to each other. In the following example Storage will stand in memory even after going out of scope, because there is cyclic referencing between Nodes

struct Node {
    next: Option<Pointer<Node>>,
}
let ptr1 = storage.create(Node { next: None });
let ptr2 = storage.create(Node { next: Some(ptr1.clone()) });
storage[&ptr1].next = Some(ptr2.clone());

To avoid such situations, just replace Option<Pointer<Node>> with Option<WeakPointer<Node>>

Example

let pointer = storage.create(1i32);
// create WeakPointer to this component
let weak = pointer.downgrade();

You will need to upgrade WeakPointer to access component in storage

let pointer = weak.upgrade()?;
storage[&pointer] = 20;

Methods

impl<T> WeakPointer<T>
[src]

[src]

Upgrades the WeakPointer to a Pointer, if possible.

Errors

Returns DeadComponentError if the related component in storage was destroyed.

Trait Implementations

impl<T: Debug> Debug for WeakPointer<T>
[src]

[src]

Formats the value using the given formatter.

impl<T> Clone for WeakPointer<T>
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl<T> PartialEq for WeakPointer<T>
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

1.0.0
[src]

This method tests for !=.

impl<T> Eq for WeakPointer<T>
[src]