Struct esp_idf_svc::espnow::EspNow

source ·
pub struct EspNow<'a>(/* private fields */);

Implementations§

source§

impl EspNow<'static>

source

pub fn take() -> Result<Self, EspError>

source§

impl<'a> EspNow<'a>

source

pub unsafe fn take_nonstatic() -> Result<Self, EspError>

§Safety

This method - in contrast to method take - allows the user to set non-static callbacks/closures into the returned EspNow service. This enables users to borrow

  • in the closure - variables that live on the stack - or more generally - in the same scope where the service is created.

HOWEVER: care should be taken NOT to call core::mem::forget() on the service, as that would immediately lead to an UB (crash). Also note that forgetting the service might happen with Rc and Arc when circular references are introduced: https://github.com/rust-lang/rust/issues/24456

The reason is that the closure is actually sent to a hidden ESP IDF thread. This means that if the service is forgotten, Rust is free to e.g. unwind the stack and the closure now owned by this other thread will end up with references to variables that no longer exist.

The destructor of the service takes care - prior to the service being dropped and e.g. the stack being unwind - to remove the closure from the hidden thread and destroy it. Unfortunately, when the service is forgotten, the un-subscription does not happen and invalid references are left dangling.

This “local borrowing” will only be possible to express in a safe way once/if !Leak types are introduced to Rust (i.e. the impossibility to “forget” a type and thus not call its destructor).

source

pub fn send(&self, peer_addr: [u8; 6], data: &[u8]) -> Result<(), EspError>

source

pub fn add_peer(&self, peer_info: PeerInfo) -> Result<(), EspError>

source

pub fn del_peer(&self, peer_addr: [u8; 6]) -> Result<(), EspError>

source

pub fn mod_peer(&self, peer_info: PeerInfo) -> Result<(), EspError>

source

pub fn get_peer(&self, peer_addr: [u8; 6]) -> Result<PeerInfo, EspError>

source

pub fn peer_exists(&self, peer_addr: [u8; 6]) -> Result<bool, EspError>

source

pub fn get_peers_number(&self) -> Result<(usize, usize), EspError>

source

pub fn fetch_peer(&self, from_head: bool) -> Result<PeerInfo, EspError>

source

pub fn set_pmk(&self, pmk: &[u8]) -> Result<(), EspError>

source

pub fn get_version(&self) -> Result<u32, EspError>

source

pub fn register_recv_cb<F>(&self, callback: F) -> Result<(), EspError>
where F: FnMut(&[u8], &[u8]) + Send + 'a,

source

pub fn unregister_recv_cb(&self) -> Result<(), EspError>

source

pub fn register_send_cb<F>(&self, callback: F) -> Result<(), EspError>
where F: FnMut(&[u8], SendStatus) + Send + 'a,

source

pub fn unregister_send_cb(&self) -> Result<(), EspError>

Trait Implementations§

source§

impl<'a> Drop for EspNow<'a>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for EspNow<'a>

§

impl<'a> Send for EspNow<'a>

§

impl<'a> Sync for EspNow<'a>

§

impl<'a> Unpin for EspNow<'a>

§

impl<'a> UnwindSafe for EspNow<'a>

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.