ic_cdk/
lib.rs

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
15pub mod api;
16pub mod bitcoin_canister;
17pub mod call;
18pub mod futures;
19mod macros;
20pub mod management_canister;
21pub mod stable;
22pub mod storage;
23
24use std::future::Future;
25
26#[doc(inline)]
27pub use api::trap;
28
29#[doc(hidden)]
30#[allow(deprecated)]
31pub use api::{
32    call::{call, notify},
33    caller, id, print,
34};
35
36#[doc(inline)]
37pub use macros::*;
38
39/// Format and then print the formatted message
40#[cfg(target_family = "wasm")]
41#[macro_export]
42macro_rules! println {
43    ($fmt:expr) => ($crate::api::debug_print(format!($fmt)));
44    ($fmt:expr, $($arg:tt)*) => ($crate::api::debug_print(format!($fmt, $($arg)*)));
45}
46
47/// Format and then print the formatted message
48#[cfg(not(target_family = "wasm"))]
49#[macro_export]
50macro_rules! println {
51    ($fmt:expr) => (std::println!($fmt));
52    ($fmt:expr, $($arg:tt)*) => (std::println!($fmt, $($arg)*));
53}
54
55/// Format and then print the formatted message
56#[cfg(target_family = "wasm")]
57#[macro_export]
58macro_rules! eprintln {
59    ($fmt:expr) => ($crate::api::debug_print(format!($fmt)));
60    ($fmt:expr, $($arg:tt)*) => ($crate::api::debug_print(format!($fmt, $($arg)*)));
61}
62
63/// Format and then print the formatted message
64#[cfg(not(target_family = "wasm"))]
65#[macro_export]
66macro_rules! eprintln {
67    ($fmt:expr) => (std::eprintln!($fmt));
68    ($fmt:expr, $($arg:tt)*) => (std::eprintln!($fmt, $($arg)*));
69}
70
71#[doc(hidden)]
72#[deprecated(
73    since = "0.18.0",
74    note = "Use ic_cdk::futures::spawn_017_compat. Alternatively, migrate to ic_cdk::futures::spawn;
75    code execution order will change, see https://github.com/dfinity/cdk-rs/blob/0.18.3/ic-cdk/V18_GUIDE.md#futures-ordering-changes"
76)]
77pub fn spawn<F: 'static + Future<Output = ()>>(fut: F) {
78    crate::futures::spawn_017_compat(fut);
79}