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_base::NetStack;
use ergot_base::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: &Header,
hdr_raw: &[u8],
body: &[u8],
) -> Result<(), NetStackSendError>
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.
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