diff options
| author | Dario Nieuwenhuis <[email protected]> | 2023-06-01 01:32:11 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2023-06-01 01:42:34 +0200 |
| commit | 1d8321b821d114b369d5a087a1a7a6600228b032 (patch) | |
| tree | 605b3eb96ea10120f7e8bf0741bcc34daab8e9ec /examples/std/src | |
| parent | d7d66bd74f2ef1bc8903b15df630ddbb8fe97df4 (diff) | |
Use make_static! from static-cell v1.1
Diffstat (limited to 'examples/std/src')
| -rw-r--r-- | examples/std/src/bin/net.rs | 18 | ||||
| -rw-r--r-- | examples/std/src/bin/net_dns.rs | 18 | ||||
| -rw-r--r-- | examples/std/src/bin/net_udp.rs | 18 | ||||
| -rw-r--r-- | examples/std/src/bin/tcp_accept.rs | 18 |
4 files changed, 28 insertions, 44 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; | |||
| 11 | use heapless::Vec; | 11 | use heapless::Vec; |
| 12 | use log::*; | 12 | use log::*; |
| 13 | use rand_core::{OsRng, RngCore}; | 13 | use rand_core::{OsRng, RngCore}; |
| 14 | use static_cell::StaticCell; | 14 | use static_cell::{make_static, StaticCell}; |
| 15 | 15 | ||
| 16 | #[path = "../tuntap.rs"] | 16 | #[path = "../tuntap.rs"] |
| 17 | mod tuntap; | 17 | mod tuntap; |
| 18 | 18 | ||
| 19 | use crate::tuntap::TunTapDevice; | 19 | use crate::tuntap::TunTapDevice; |
| 20 | |||
| 21 | macro_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")] |
| 31 | struct Opts { | 22 | struct 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(); |
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}; | |||
| 9 | use heapless::Vec; | 9 | use heapless::Vec; |
| 10 | use log::*; | 10 | use log::*; |
| 11 | use rand_core::{OsRng, RngCore}; | 11 | use rand_core::{OsRng, RngCore}; |
| 12 | use static_cell::StaticCell; | 12 | use static_cell::{make_static, StaticCell}; |
| 13 | 13 | ||
| 14 | #[path = "../tuntap.rs"] | 14 | #[path = "../tuntap.rs"] |
| 15 | mod tuntap; | 15 | mod tuntap; |
| 16 | 16 | ||
| 17 | use crate::tuntap::TunTapDevice; | 17 | use crate::tuntap::TunTapDevice; |
| 18 | |||
| 19 | macro_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")] |
| 29 | struct Opts { | 20 | struct 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(); |
diff --git a/examples/std/src/bin/net_udp.rs b/examples/std/src/bin/net_udp.rs index 4df23edf6..d89ec7643 100644 --- a/examples/std/src/bin/net_udp.rs +++ b/examples/std/src/bin/net_udp.rs | |||
| @@ -7,21 +7,12 @@ use embassy_net::{Config, Ipv4Address, Ipv4Cidr, Stack, StackResources}; | |||
| 7 | use heapless::Vec; | 7 | use heapless::Vec; |
| 8 | use log::*; | 8 | use log::*; |
| 9 | use rand_core::{OsRng, RngCore}; | 9 | use rand_core::{OsRng, RngCore}; |
| 10 | use static_cell::StaticCell; | 10 | use static_cell::{make_static, StaticCell}; |
| 11 | 11 | ||
| 12 | #[path = "../tuntap.rs"] | 12 | #[path = "../tuntap.rs"] |
| 13 | mod tuntap; | 13 | mod tuntap; |
| 14 | 14 | ||
| 15 | use crate::tuntap::TunTapDevice; | 15 | use crate::tuntap::TunTapDevice; |
| 16 | |||
| 17 | macro_rules! singleton { | ||
| 18 | ($val:expr) => {{ | ||
| 19 | type T = impl Sized; | ||
| 20 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); | ||
| 21 | STATIC_CELL.init_with(move || $val) | ||
| 22 | }}; | ||
| 23 | } | ||
| 24 | |||
| 25 | #[derive(Parser)] | 16 | #[derive(Parser)] |
| 26 | #[clap(version = "1.0")] | 17 | #[clap(version = "1.0")] |
| 27 | struct Opts { | 18 | struct Opts { |
| @@ -62,7 +53,12 @@ async fn main_task(spawner: Spawner) { | |||
| 62 | let seed = u64::from_le_bytes(seed); | 53 | let seed = u64::from_le_bytes(seed); |
| 63 | 54 | ||
| 64 | // Init network stack | 55 | // Init network stack |
| 65 | let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<3>::new()), seed)); | 56 | let stack = &*make_static!(Stack::new( |
| 57 | device, | ||
| 58 | config, | ||
| 59 | make_static!(StackResources::<3>::new()), | ||
| 60 | seed | ||
| 61 | )); | ||
| 66 | 62 | ||
| 67 | // Launch network task | 63 | // Launch network task |
| 68 | spawner.spawn(net_task(stack)).unwrap(); | 64 | spawner.spawn(net_task(stack)).unwrap(); |
diff --git a/examples/std/src/bin/tcp_accept.rs b/examples/std/src/bin/tcp_accept.rs index 97ce77f42..d24e218dc 100644 --- a/examples/std/src/bin/tcp_accept.rs +++ b/examples/std/src/bin/tcp_accept.rs | |||
| @@ -12,21 +12,12 @@ use embedded_io::asynch::Write as _; | |||
| 12 | use heapless::Vec; | 12 | use heapless::Vec; |
| 13 | use log::*; | 13 | use log::*; |
| 14 | use rand_core::{OsRng, RngCore}; | 14 | use rand_core::{OsRng, RngCore}; |
| 15 | use static_cell::StaticCell; | 15 | use static_cell::{make_static, StaticCell}; |
| 16 | 16 | ||
| 17 | #[path = "../tuntap.rs"] | 17 | #[path = "../tuntap.rs"] |
| 18 | mod tuntap; | 18 | mod tuntap; |
| 19 | 19 | ||
| 20 | use crate::tuntap::TunTapDevice; | 20 | use crate::tuntap::TunTapDevice; |
| 21 | |||
| 22 | macro_rules! singleton { | ||
| 23 | ($val:expr) => {{ | ||
| 24 | type T = impl Sized; | ||
| 25 | static STATIC_CELL: StaticCell<T> = StaticCell::new(); | ||
| 26 | STATIC_CELL.init_with(move || $val) | ||
| 27 | }}; | ||
| 28 | } | ||
| 29 | |||
| 30 | #[derive(Parser)] | 21 | #[derive(Parser)] |
| 31 | #[clap(version = "1.0")] | 22 | #[clap(version = "1.0")] |
| 32 | struct Opts { | 23 | struct Opts { |
| @@ -77,7 +68,12 @@ async fn main_task(spawner: Spawner) { | |||
| 77 | let seed = u64::from_le_bytes(seed); | 68 | let seed = u64::from_le_bytes(seed); |
| 78 | 69 | ||
| 79 | // Init network stack | 70 | // Init network stack |
| 80 | let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<3>::new()), seed)); | 71 | let stack = &*make_static!(Stack::new( |
| 72 | device, | ||
| 73 | config, | ||
| 74 | make_static!(StackResources::<3>::new()), | ||
| 75 | seed | ||
| 76 | )); | ||
| 81 | 77 | ||
| 82 | // Launch network task | 78 | // Launch network task |
| 83 | spawner.spawn(net_task(stack)).unwrap(); | 79 | spawner.spawn(net_task(stack)).unwrap(); |
