aboutsummaryrefslogtreecommitdiff
path: root/examples/std/src/bin/net.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.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.rs')
-rw-r--r--examples/std/src/bin/net.rs18
1 files changed, 7 insertions, 11 deletions
diff --git a/examples/std/src/bin/net.rs b/examples/std/src/bin/net.rs
index d93616254..b42bfc13b 100644
--- a/examples/std/src/bin/net.rs
+++ b/examples/std/src/bin/net.rs
@@ -11,21 +11,12 @@ use embedded_io::asynch::Write;
11use heapless::Vec; 11use heapless::Vec;
12use log::*; 12use log::*;
13use rand_core::{OsRng, RngCore}; 13use rand_core::{OsRng, RngCore};
14use static_cell::StaticCell; 14use static_cell::{make_static, StaticCell};
15 15
16#[path = "../tuntap.rs"] 16#[path = "../tuntap.rs"]
17mod tuntap; 17mod tuntap;
18 18
19use crate::tuntap::TunTapDevice; 19use crate::tuntap::TunTapDevice;
20
21macro_rules! singleton {
22 ($val:expr) => {{
23 type T = impl Sized;
24 static STATIC_CELL: StaticCell<T> = StaticCell::new();
25 STATIC_CELL.init_with(move || $val)
26 }};
27}
28
29#[derive(Parser)] 20#[derive(Parser)]
30#[clap(version = "1.0")] 21#[clap(version = "1.0")]
31struct Opts { 22struct Opts {
@@ -66,7 +57,12 @@ async fn main_task(spawner: Spawner) {
66 let seed = u64::from_le_bytes(seed); 57 let seed = u64::from_le_bytes(seed);
67 58
68 // Init network stack 59 // Init network stack
69 let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<3>::new()), seed)); 60 let stack = &*make_static!(Stack::new(
61 device,
62 config,
63 make_static!(StackResources::<3>::new()),
64 seed
65 ));
70 66
71 // Launch network task 67 // Launch network task
72 spawner.spawn(net_task(stack)).unwrap(); 68 spawner.spawn(net_task(stack)).unwrap();