aboutsummaryrefslogtreecommitdiff
path: root/examples/std/src/bin/net_dns.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2023-05-31 23:49:00 +0000
committerGitHub <[email protected]>2023-05-31 23:49:00 +0000
commitc036eab62c2221bd8f458bd6edd1562dfcdb8421 (patch)
tree605b3eb96ea10120f7e8bf0741bcc34daab8e9ec /examples/std/src/bin/net_dns.rs
parentd7d66bd74f2ef1bc8903b15df630ddbb8fe97df4 (diff)
parent1d8321b821d114b369d5a087a1a7a6600228b032 (diff)
Merge pull request #1523 from embassy-rs/static-cell
Use make_static! from static-cell v1.1
Diffstat (limited to 'examples/std/src/bin/net_dns.rs')
-rw-r--r--examples/std/src/bin/net_dns.rs18
1 files changed, 7 insertions, 11 deletions
diff --git a/examples/std/src/bin/net_dns.rs b/examples/std/src/bin/net_dns.rs
index d1e1f8212..932ac5831 100644
--- a/examples/std/src/bin/net_dns.rs
+++ b/examples/std/src/bin/net_dns.rs
@@ -9,21 +9,12 @@ use embassy_net::{Config, Ipv4Address, Ipv4Cidr, Stack, StackResources};
9use heapless::Vec; 9use heapless::Vec;
10use log::*; 10use log::*;
11use rand_core::{OsRng, RngCore}; 11use rand_core::{OsRng, RngCore};
12use static_cell::StaticCell; 12use static_cell::{make_static, StaticCell};
13 13
14#[path = "../tuntap.rs"] 14#[path = "../tuntap.rs"]
15mod tuntap; 15mod tuntap;
16 16
17use crate::tuntap::TunTapDevice; 17use crate::tuntap::TunTapDevice;
18
19macro_rules! singleton {
20 ($val:expr) => {{
21 type T = impl Sized;
22 static STATIC_CELL: StaticCell<T> = StaticCell::new();
23 STATIC_CELL.init_with(move || $val)
24 }};
25}
26
27#[derive(Parser)] 18#[derive(Parser)]
28#[clap(version = "1.0")] 19#[clap(version = "1.0")]
29struct Opts { 20struct Opts {
@@ -65,7 +56,12 @@ async fn main_task(spawner: Spawner) {
65 let seed = u64::from_le_bytes(seed); 56 let seed = u64::from_le_bytes(seed);
66 57
67 // Init network stack 58 // Init network stack
68 let stack: &Stack<_> = &*singleton!(Stack::new(device, config, singleton!(StackResources::<3>::new()), seed)); 59 let stack: &Stack<_> = &*make_static!(Stack::new(
60 device,
61 config,
62 make_static!(StackResources::<3>::new()),
63 seed
64 ));
69 65
70 // Launch network task 66 // Launch network task
71 spawner.spawn(net_task(stack)).unwrap(); 67 spawner.spawn(net_task(stack)).unwrap();