Struct header_vec::HeaderVec[][src]

pub struct HeaderVec<H, T> { /* fields omitted */ }
Expand description

A vector with a header of your choosing, behind a thin pointer

Example

use core::mem::size_of_val;
use header_vec::HeaderVec;

#[derive(Debug)]
struct OurHeaderType {
    a: usize,
}

let h = OurHeaderType{ a: 2 };
let mut hv = HeaderVec::<OurHeaderType, char>::new(h);
hv.push('x');
hv.push('z');

println!("HeaderVec itself consists solely of a pointer, it's only {} bytes big.", size_of_val(&hv));
println!("All of the data, like our header, {:?}, and the length of the vector: {}, resides on the other side of the pointer.", &*hv, hv.len());
HeaderVec itself consists solely of a pointer, it's only 8 bytes big.
All of the data, like our header, OurHeaderType { a: 2 }, and the length of the vector: 2, resides on the other side of the pointer.

Implementations

This is useful to check if two nodes are the same. Use it with HeaderVec::is.

This is used to check if this is the HeaderVec that corresponds to the given pointer. This is useful for updating weak references after HeaderVec::push returns the pointer.

Create a (dangerous) weak reference to the HeaderVec. This is useful to be able to create, for instance, graph data structures. Edges can utilize HeaderVecWeak so that they can traverse the graph immutably without needing to go to memory twice to look up first the pointer to the underlying dynamic edge store (like a Vec). The caveat is that the user is responsible for updating all HeaderVecWeak if the HeaderVec needs to reallocate when HeaderVec::push is called. HeaderVec::push returns true when it reallocates, and this indicates that the HeaderVecWeak need to be updated. Therefore, this works best for implemented undirected graphs where it is easy to find neighbor nodes. Directed graphs with an alternative method to traverse directed edges backwards should also work with this technique.

Safety

A HeaderVecWeak can only be used while its corresponding HeaderVec is still alive. HeaderVecWeak also MUST be updated manually by the user when HeaderVec::push returns true, since the pointer has now changed. As there is no reference counting mechanism, or method by which all the weak references could be updated, it is up to the user to do this. That is why this is unsafe. Make sure you update your HeaderVecWeak appropriately.

If a HeaderVec is updated through a weak reference and reallocates, you must use this method to update the internal pointer to the HeaderVec (along with any other weak references).

Safety

See the safety section in HeaderVec::weak for an explanation of why this is necessary.

Adds an item to the end of the list.

Returns true if the memory was moved to a new location. In this case, you are responsible for updating the weak nodes.

Retains only the elements specified by the predicate.

In other words, remove all elements e such that f(&e) returns false. This method operates in place, visiting each element exactly once in the original order, and preserves the order of the retained elements.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

The resulting type after dereferencing.

Dereferences the value.

Mutably dereferences the value.

Executes the destructor for this type. Read more

The returned type after indexing.

Performs the indexing (container[index]) operation. Read more

Performs the mutable indexing (container[index]) operation. Read more

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

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.