ic_stable_memory/utils/
mod.rs

1//! Various utilities used by this crate
2
3#[doc(hidden)]
4pub mod certification;
5#[doc(hidden)]
6pub mod math;
7pub mod mem_context;
8#[cfg(test)]
9pub mod test;
10
11#[cfg(target_family = "wasm")]
12use ic_cdk::print;
13
14#[cfg(target_family = "wasm")]
15#[inline]
16pub fn isoprint(str: &str) {
17    print(str)
18}
19
20/// Prints a value to stdout. Locally uses `println!` macro, on canister uses [ic_cdk::print] function.
21#[cfg(not(target_family = "wasm"))]
22#[inline]
23pub fn isoprint(str: &str) {
24    println!("{}", str)
25}
26
27/// Unwraps a [Result], but does not require [Debug] to be implemented on `T`
28pub trait DebuglessUnwrap<T> {
29    #[doc(hidden)]
30    fn debugless_unwrap(self) -> T;
31}
32
33impl<R, E> DebuglessUnwrap<R> for Result<R, E> {
34    fn debugless_unwrap(self) -> R {
35        match self {
36            Err(_) => panic!("Unwrapped a Result type without debug info"),
37            Ok(r) => r,
38        }
39    }
40}