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