Struct NetStack

Source
pub struct NetStack<R: ScopedRawMutex, P: Profile> { /* private fields */ }
Expand description

The Ergot Netstack

Implementations§

Source§

impl<R, P> NetStack<R, P>

Source

pub const fn new() -> Self

Create a new, uninitialized NetStack.

Requires that the ScopedRawMutex implements the mutex::ConstInit trait, and the Profile implements the interface_manager::ConstInit trait.

§Example
use mutex::raw_impls::cs::CriticalSectionRawMutex as CSRMutex;
use ergot_base::NetStack;
use ergot_base::interface_manager::profiles::null::Null;

static STACK: NetStack<CSRMutex, Null> = NetStack::new();
Source§

impl<R, P> NetStack<R, P>

Source

pub const fn new_with_profile(p: P) -> Self

Source§

impl<R, P> NetStack<R, P>

Source

pub fn new_arc(p: P) -> Arc<Self>

Source§

impl<R, P> NetStack<R, P>
where R: ScopedRawMutex, P: Profile,

Source

pub const fn const_new(r: R, p: P) -> Self

Manually create a new, uninitialized NetStack.

This method is useful if your ScopedRawMutex or Profile do not implement their corresponding ConstInit trait.

In general, this is most often only needed for loom testing, and NetStack::new() should be used when possible.

Source

pub fn manage_profile<F: FnOnce(&mut P) -> U, U>(&self, f: F) -> U

Access the contained Profile.

Access to the Profile is made via the provided closure. The BlockingMutex is locked for the duration of this access, inhibiting all other usage of this NetStack.

This can be used to add new interfaces, obtain metadata, or other actions supported by the chosen Profile.

§Example
static STACK: NetStack<CSRMutex, Null> = NetStack::new();

let res = STACK.manage_profile(|im| {
   // The mutex is locked for the full duration of this closure.
   // We can return whatever we want from this context, though not
   // anything borrowed from `im`.
   42
});
assert_eq!(res, 42);
Source

pub fn send_raw( &self, hdr: &Header, hdr_raw: &[u8], body: &[u8], ) -> Result<(), NetStackSendError>

Send a raw (pre-serialized) message.

This interface should almost never be used by end-users, and is instead typically used by interfaces to feed received messages into the NetStack.

Source

pub fn send_ty<T: 'static + Serialize + Clone>( &self, hdr: &Header, t: &T, ) -> Result<(), NetStackSendError>

Send a typed message

Source

pub fn send_err( &self, hdr: &Header, err: ProtocolError, ) -> Result<(), NetStackSendError>

Trait Implementations§

Source§

impl<R, P> Default for NetStack<R, P>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<R, P> NetStackHandle for &NetStack<R, P>
where R: ScopedRawMutex, P: Profile,

Source§

type Mutex = R

Source§

type Profile = P

Source§

type Target = &NetStack<R, P>

Source§

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

Auto Trait Implementations§

§

impl<R, P> !Freeze for NetStack<R, P>

§

impl<R, P> !RefUnwindSafe for NetStack<R, P>

§

impl<R, P> Send for NetStack<R, P>
where R: Send, P: Send,

§

impl<R, P> Sync for NetStack<R, P>
where R: Sync, P: Send,

§

impl<R, P> Unpin for NetStack<R, P>
where R: Unpin, P: Unpin,

§

impl<R, P> !UnwindSafe for NetStack<R, P>

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.