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