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 mod export {
37 pub use candid;
38 pub use candid::Principal;
39 pub use serde;
40}
41
42pub fn setup() {
44 if !DONE.swap(true, Ordering::SeqCst) {
45 printer::hook()
46 }
47}
48
49#[deprecated(
51 since = "0.3.4",
52 note = "Use the spawn() function instead, it does the same thing but is more appropriately named."
53)]
54pub fn block_on<F: 'static + std::future::Future<Output = ()>>(future: F) {
55 ic_cdk_executor::spawn(future);
56}
57
58pub fn spawn<F: 'static + std::future::Future<Output = ()>>(future: F) {
61 ic_cdk_executor::spawn(future);
62}
63
64#[cfg(target_arch = "wasm32")]
66#[macro_export]
67macro_rules! println {
68 ($fmt:expr) => ($crate::print(format!($fmt)));
69 ($fmt:expr, $($arg:tt)*) => ($crate::print(format!($fmt, $($arg)*)));
70}
71
72#[cfg(not(target_arch = "wasm32"))]
74#[macro_export]
75macro_rules! println {
76 ($fmt:expr) => (std::println!($fmt));
77 ($fmt:expr, $($arg:tt)*) => (std::println!($fmt, $($arg)*));
78}
79
80#[cfg(target_arch = "wasm32")]
82#[macro_export]
83macro_rules! eprintln {
84 ($fmt:expr) => ($crate::print(format!($fmt)));
85 ($fmt:expr, $($arg:tt)*) => ($crate::print(format!($fmt, $($arg)*)));
86}
87
88#[cfg(not(target_arch = "wasm32"))]
90#[macro_export]
91macro_rules! eprintln {
92 ($fmt:expr) => (std::eprintln!($fmt));
93 ($fmt:expr, $($arg:tt)*) => (std::eprintln!($fmt, $($arg)*));
94}