pub struct NetStack<R: ScopedRawMutex, P: Profile> { /* private fields */ }Expand description
The Ergot Netstack
Implementations§
Source§impl<R, P> NetStack<R, P>
impl<R, P> NetStack<R, P>
Sourcepub const fn new() -> Self
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>
impl<R, P> NetStack<R, P>
pub const fn new_with_profile(p: P) -> Self
Source§impl<R, P> NetStack<R, P>where
R: ScopedRawMutex,
P: Profile,
impl<R, P> NetStack<R, P>where
R: ScopedRawMutex,
P: Profile,
Sourcepub const fn const_new(r: R, p: P) -> Self
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.
Sourcepub fn manage_profile<F: FnOnce(&mut P) -> U, U>(&self, f: F) -> U
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);Sourcepub fn send_raw(
&self,
hdr: &HeaderSeq,
body: &[u8],
source: P::InterfaceIdent,
) -> Result<(), NetStackSendError>
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.
Sourcepub fn send_ty<T: 'static + Serialize + Clone>(
&self,
hdr: &Header,
t: &T,
) -> Result<(), NetStackSendError>
pub fn send_ty<T: 'static + Serialize + Clone>( &self, hdr: &Header, t: &T, ) -> Result<(), NetStackSendError>
Send a typed message
pub fn send_bor<T: Serialize>( &self, hdr: &Header, t: &T, ) -> Result<(), NetStackSendError>
pub fn send_err( &self, hdr: &Header, err: ProtocolError, source: Option<P::InterfaceIdent>, ) -> Result<(), NetStackSendError>
Sourcepub fn with_sockets<F, U>(&self, f: F) -> Option<U>where
for<'b> F: FnOnce(SocketHeaderIter<'b>) -> U,
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,
impl<R, P> NetStack<R, P>where
R: ScopedRawMutex,
P: Profile,
Sourcepub fn trace_fmt(&self, args: &Arguments<'_>)
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
Sourcepub fn debug_fmt(&self, args: &Arguments<'_>)
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
Sourcepub fn info_fmt(&self, args: &Arguments<'_>)
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
Sourcepub fn warn_fmt(&self, args: &Arguments<'_>)
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
Sourcepub fn error_fmt(&self, args: &Arguments<'_>)
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