Struct HeaderVecWeak

Source
pub struct HeaderVecWeak<H, T> { /* private fields */ }

Methods from Deref<Target = HeaderVec<H, T>>§

Source

pub fn len(&self) -> usize

Examples found in repository?
examples/doc_example.rs (line 23)
10fn main() {
11    let h = OurHeaderType { a: 2 };
12    let mut hv = HeaderVec::<OurHeaderType, char>::new(h);
13    hv.push('x');
14    hv.push('z');
15
16    println!(
17        "[`HeaderVec`] itself consists solely of a pointer, it's only {} bytes big.",
18        size_of_val(&hv)
19    );
20    println!(
21        "All of the data, like our header `{:?}`, the length of the vector: `{}`,",
22        &*hv,
23        hv.len()
24    );
25    println!(
26        "and the contents of the vector `{:?}` resides on the other side of the pointer.",
27        hv.as_slice()
28    );
29}
Source

pub fn is_empty(&self) -> bool

Source

pub fn capacity(&self) -> usize

Source

pub fn as_slice(&self) -> &[T]

Examples found in repository?
examples/doc_example.rs (line 27)
10fn main() {
11    let h = OurHeaderType { a: 2 };
12    let mut hv = HeaderVec::<OurHeaderType, char>::new(h);
13    hv.push('x');
14    hv.push('z');
15
16    println!(
17        "[`HeaderVec`] itself consists solely of a pointer, it's only {} bytes big.",
18        size_of_val(&hv)
19    );
20    println!(
21        "All of the data, like our header `{:?}`, the length of the vector: `{}`,",
22        &*hv,
23        hv.len()
24    );
25    println!(
26        "and the contents of the vector `{:?}` resides on the other side of the pointer.",
27        hv.as_slice()
28    );
29}
Source

pub fn as_mut_slice(&mut self) -> &mut [T]

Source

pub fn ptr(&self) -> *const ()

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

Source

pub fn is(&self, ptr: *const ()) -> bool

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.

Source

pub unsafe fn weak(&self) -> HeaderVecWeak<H, T>

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.

Source

pub unsafe fn update(&mut self, weak: HeaderVecWeak<H, T>)

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.

Source

pub fn push(&mut self, item: T) -> Option<*const ()>

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.

Examples found in repository?
examples/doc_example.rs (line 13)
10fn main() {
11    let h = OurHeaderType { a: 2 };
12    let mut hv = HeaderVec::<OurHeaderType, char>::new(h);
13    hv.push('x');
14    hv.push('z');
15
16    println!(
17        "[`HeaderVec`] itself consists solely of a pointer, it's only {} bytes big.",
18        size_of_val(&hv)
19    );
20    println!(
21        "All of the data, like our header `{:?}`, the length of the vector: `{}`,",
22        &*hv,
23        hv.len()
24    );
25    println!(
26        "and the contents of the vector `{:?}` resides on the other side of the pointer.",
27        hv.as_slice()
28    );
29}
Source

pub fn retain(&mut self, f: impl FnMut(&T) -> bool)

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§

Source§

impl<H, T> Debug for HeaderVecWeak<H, T>

Source§

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

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

impl<H, T> Deref for HeaderVecWeak<H, T>

Source§

type Target = HeaderVec<H, T>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<H, T> DerefMut for HeaderVecWeak<H, T>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

§

impl<H, T> Freeze for HeaderVecWeak<H, T>

§

impl<H, T> RefUnwindSafe for HeaderVecWeak<H, T>

§

impl<H, T> !Send for HeaderVecWeak<H, T>

§

impl<H, T> !Sync for HeaderVecWeak<H, T>

§

impl<H, T> Unpin for HeaderVecWeak<H, T>
where H: Unpin,

§

impl<H, T> UnwindSafe for HeaderVecWeak<H, T>

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.