1#![warn(
2 elided_lifetimes_in_paths,
3 missing_debug_implementations,
4 missing_docs,
5 unsafe_op_in_unsafe_fn,
6 clippy::undocumented_unsafe_blocks,
7 clippy::missing_safety_doc
8)]
9#![cfg_attr(docsrs, feature(doc_cfg))]
10
11#[cfg(target_feature = "atomics")]
18compile_error!("This version of the CDK does not support multithreading.");
19
20#[doc(inline)]
21pub use ic_cdk_macros::*;
22
23pub mod api;
24mod printer;
25pub mod storage;
26
27use std::sync::atomic::{AtomicBool, Ordering};
28
29pub use api::call::call;
30pub use api::call::notify;
31pub use api::{caller, id, print, trap};
32
33static DONE: AtomicBool = AtomicBool::new(false);
34
35pub fn setup() {
37 if !DONE.swap(true, Ordering::SeqCst) {
38 printer::hook()
39 }
40}
41
42#[deprecated(
44 since = "0.3.4",
45 note = "Use the spawn() function instead, it does the same thing but is more appropriately named."
46)]
47pub fn block_on<F: 'static + std::future::Future<Output = ()>>(future: F) {
48 ic_cdk_executor::spawn(future);
49}
50
51pub fn spawn<F: 'static + std::future::Future<Output = ()>>(future: F) {
54 ic_cdk_executor::spawn(future);
55}
56
57#[cfg(target_arch = "wasm32")]
59#[macro_export]
60macro_rules! println {
61 ($fmt:expr) => ($crate::print(format!($fmt)));
62 ($fmt:expr, $($arg:tt)*) => ($crate::print(format!($fmt, $($arg)*)));
63}
64
65#[cfg(not(target_arch = "wasm32"))]
67#[macro_export]
68macro_rules! println {
69 ($fmt:expr) => (std::println!($fmt));
70 ($fmt:expr, $($arg:tt)*) => (std::println!($fmt, $($arg)*));
71}
72
73#[cfg(target_arch = "wasm32")]
75#[macro_export]
76macro_rules! eprintln {
77 ($fmt:expr) => ($crate::print(format!($fmt)));
78 ($fmt:expr, $($arg:tt)*) => ($crate::print(format!($fmt, $($arg)*)));
79}
80
81#[cfg(not(target_arch = "wasm32"))]
83#[macro_export]
84macro_rules! eprintln {
85 ($fmt:expr) => (std::eprintln!($fmt));
86 ($fmt:expr, $($arg:tt)*) => (std::eprintln!($fmt, $($arg)*));
87}