NetStack

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::NetStack;
use ergot::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>
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: &HeaderSeq, body: &[u8], source: P::InterfaceIdent, ) -> 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_bor<T: Serialize>( &self, hdr: &Header, t: &T, ) -> Result<(), NetStackSendError>

Source

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

Source

pub fn with_sockets<F, U>(&self, f: F) -> Option<U>
where for<'b> F: FnOnce(SocketHeaderIter<'b>) -> U,

Call the given function with an iterator over all discoverable sockets

Returns None if the mutex is already locked.

Source§

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

Source

pub fn trace_fmt(&self, args: &Arguments<'_>)

Send a trace-level formatted message to the ErgotFmtTxTopic as a broadcast topic message

You can use crate::fmt! or core::format_args! to create the value passed to this function

Source

pub fn debug_fmt(&self, args: &Arguments<'_>)

Send a debug-level formatted message to the ErgotFmtTxTopic as a broadcast topic message

You can use crate::fmt! or core::format_args! to create the value passed to this function

Source

pub fn info_fmt(&self, args: &Arguments<'_>)

Send an info-level formatted message to the ErgotFmtTxTopic as a broadcast topic message

You can use crate::fmt! or core::format_args! to create the value passed to this function

Source

pub fn warn_fmt(&self, args: &Arguments<'_>)

Send a warn-level formatted message to the ErgotFmtTxTopic as a broadcast topic message

You can use crate::fmt! or core::format_args! to create the value passed to this function

Source

pub fn error_fmt(&self, args: &Arguments<'_>)

Send an error-level formatted message to the ErgotFmtTxTopic as a broadcast topic message

You can use crate::fmt! or core::format_args! to create the value passed to this function

Source

pub fn services(&self) -> Services<&Self>

Source

pub fn endpoints(&self) -> Endpoints<&Self>

Source

pub fn topics(&self) -> Topics<&Self>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V