Skip to main content

MainRef

Struct MainRef 

Source
pub struct MainRef(/* private fields */);
Expand description

Reference to VPP per-thread main library context

This is a safe wrapper around vlib_main_t, providing access to its fields.

A &mut MainRef is equivalent to a vlib_main_t * in C (a *mut vlib_main_t in Rust).

See also BarrierHeldMainRef for a variant that indicates the caller holds the main thread barrier.

Implementations§

Source§

impl MainRef

Source

pub unsafe fn get_buffers<'a, 'me, 'buf: 'me, FeatureData, const N: usize>( &'me self, from_indices: &'a [u32], to: &mut ArrayVec<&'buf mut BufferRef<FeatureData>, N>, )

Get pointers to buffers for the given buffer indices, writing them into the provided to arrayvec.

This is similar to vlib_get_buffers in the C API.

Note that although it would be more idiomatic to return an ArrayVec directly, this method takes a mutable reference to an ArrayVec to avoid an unnecessary copy when returning.

§Safety
  • The caller must ensure that to has enough capacity to hold all the buffers corresponding to the indices in from_indices.
  • Each index in from_indices must be valid and the caller must have ownership of the buffer it corresponds to.
  • Each buffer’s feature_arc_index and current_config_index must be consistent with the FeatureData type. If they are not known (i.e. because the caller the node isn’t being executed in a feature arc), FeatureData should be a zero-sized type such as ().
  • The capacity of from_indices must be a multiple of 8 (note though that the length is allowed not to be). In other words, it must be valid to read multiples of 8 from the underlying memory (possibly returning uninitialised or stale data) without faulting.
Source

pub unsafe fn buffer_enqueue_to_next<N: Node, V: VectorBufferIndex>( &self, node: &mut NodeRuntimeRef<N>, from: &[V], nexts: &[u16], )

Enqueues a slice of buffer indices to a next node

This corresponds to the VPP C function vlib_buffer_enqueue_to_next.

§Safety
  • The length of the from and next slices must match.
  • The next node must have a Vector type of u32 (or the C equivalent).
  • The next node must have a Scalar type of () (or the C equivalent).
  • The next node must have an Aux type of () (or the C equivalent).
  • vlib_buffer_func_main must have been filled in with valid function pointers (which will be done by VPP at initialisation time).
  • The buffer state, such as current_data and length must be set according to the preconditions of the next node.
  • Each entry in the from slice must be a valid index to a buffer.
  • Each entry in the nexts slice must be a valid next node index.
Source§

impl MainRef

Source

pub unsafe fn from_ptr_mut<'a>(ptr: *mut vlib_main_t) -> &'a mut Self

Creates a &mut MainRef directly from a pointer

§Safety
  • The pointer must be valid and a properly initialised vlib_main_t for the thread.
  • The pointer must stay valid and the contents must not be mutated for the duration of the lifetime of the returned object.
  • The vlib_main_t must have been created by VPP at startup and not manually by the caller, as many datastructures size the memory they allocate by the number of threads at startup and are subsequently indexed by thread index.
Source

pub fn as_ptr(&self) -> *mut vlib_main_t

Returns the raw pointer to the underlying vlib_main_t

Source

pub fn thread_index(&self) -> u16

Returns the 0-based thread index of this VPP main context

Auto Trait Implementations§

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