1#![deny(unused_extern_crates)]
26#![warn(missing_docs, rust_2018_idioms, unreachable_pub)]
27
28#[macro_use]
29extern crate serde;
30
31macro_rules! lazy_static {
32 ($init:expr => $type:ty) => {{
33 static mut VALUE: Option<$type> = None;
34 static INIT: std::sync::Once = std::sync::Once::new();
35
36 INIT.call_once(|| unsafe { VALUE = Some($init) });
37 unsafe { VALUE.as_ref() }.expect("failed to get lazy static value")
38 }};
39}
40
41pub mod api;
42pub mod builder;
43pub mod client;
44pub mod error;
45pub mod node;
46pub mod node_manager;
47#[cfg(feature = "storage")]
48#[cfg_attr(docsrs, doc(cfg(feature = "storage")))]
49pub mod storage;
50
51pub use bee_common as common;
52pub use bee_message;
53pub use bee_pow as pow;
54pub use bee_rest_api;
55pub use builder::ClientBuilder;
56pub use client::*;
57pub use crypto::{self, keys::slip10::Seed};
58pub use error::*;
59#[cfg(feature = "mqtt")]
60pub use node::Topic;
61pub use node::{OutputType, OutputsOptions as AddressOutputsOptions};
62#[cfg(feature = "storage")]
63pub use storage::*;
64pub use url::Url;
65
66#[cfg(feature = "mqtt")]
67mod async_runtime {
68 use once_cell::sync::OnceCell;
69 use tokio::runtime::Runtime;
70
71 use std::sync::Mutex;
72
73 static RUNTIME: OnceCell<Mutex<Runtime>> = OnceCell::new();
74
75 pub(crate) fn block_on<C: futures::Future>(cb: C) -> C::Output {
76 let runtime = RUNTIME.get_or_init(|| Mutex::new(Runtime::new().expect("Failed to create Tokio runtim")));
77 runtime.lock().expect("Failed to lock the runtime.").block_on(cb)
78 }
79
80 pub(crate) fn spawn<F>(future: F)
81 where
82 F: futures::Future + Send + 'static,
83 F::Output: Send + 'static,
84 {
85 let runtime = RUNTIME.get_or_init(|| Mutex::new(Runtime::new().expect("Failed to create Tokio runtim")));
86 runtime.lock().expect("Failed to lock the runtime.").spawn(future);
87 }
88}