aboutsummaryrefslogtreecommitdiff
path: root/embassy-net/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-net/src/lib.rs')
-rw-r--r--embassy-net/src/lib.rs26
1 files changed, 24 insertions, 2 deletions
diff --git a/embassy-net/src/lib.rs b/embassy-net/src/lib.rs
index 3e83da7aa..840d7a09a 100644
--- a/embassy-net/src/lib.rs
+++ b/embassy-net/src/lib.rs
@@ -57,7 +57,7 @@ pub struct StackResources<const SOCK: usize> {
57 57
58impl<const SOCK: usize> StackResources<SOCK> { 58impl<const SOCK: usize> StackResources<SOCK> {
59 /// Create a new set of stack resources. 59 /// Create a new set of stack resources.
60 pub fn new() -> Self { 60 pub const fn new() -> Self {
61 #[cfg(feature = "dns")] 61 #[cfg(feature = "dns")]
62 const INIT: Option<dns::DnsQuery> = None; 62 const INIT: Option<dns::DnsQuery> = None;
63 Self { 63 Self {
@@ -419,7 +419,29 @@ impl<D: Driver + 'static> Stack<D> {
419 }) 419 })
420 .await?; 420 .await?;
421 421
422 use embassy_hal_common::drop::OnDrop; 422 #[must_use = "to delay the drop handler invocation to the end of the scope"]
423 struct OnDrop<F: FnOnce()> {
424 f: core::mem::MaybeUninit<F>,
425 }
426
427 impl<F: FnOnce()> OnDrop<F> {
428 fn new(f: F) -> Self {
429 Self {
430 f: core::mem::MaybeUninit::new(f),
431 }
432 }
433
434 fn defuse(self) {
435 core::mem::forget(self)
436 }
437 }
438
439 impl<F: FnOnce()> Drop for OnDrop<F> {
440 fn drop(&mut self) {
441 unsafe { self.f.as_ptr().read()() }
442 }
443 }
444
423 let drop = OnDrop::new(|| { 445 let drop = OnDrop::new(|| {
424 self.with_mut(|s, i| { 446 self.with_mut(|s, i| {
425 let socket = s.sockets.get_mut::<dns::Socket>(i.dns_socket); 447 let socket = s.sockets.get_mut::<dns::Socket>(i.dns_socket);