1#![doc(html_root_url = "https://docs.rs/ic-oss-types/latest")]
2#![allow(clippy::needless_doctest_main)]
3
4use candid::Nat;
5use ciborium::into_writer;
6use num_traits::cast::ToPrimitive;
7use serde::Serialize;
8use std::collections::BTreeMap;
9
10pub mod bucket;
11pub mod cluster;
12pub mod cose;
13pub mod file;
14pub mod folder;
15pub mod permission;
16
17pub type MapValue =
19 BTreeMap<String, icrc_ledger_types::icrc::generic_metadata_value::MetadataValue>;
20
21pub fn format_error<T>(err: T) -> String
22where
23 T: std::fmt::Debug,
24{
25 format!("{:?}", err)
26}
27
28pub fn crc32(data: &[u8]) -> u32 {
29 let mut h = crc32fast::Hasher::new();
30 h.update(data);
31 h.finalize()
32}
33
34pub fn nat_to_u64(nat: &Nat) -> u64 {
35 nat.0.to_u64().unwrap_or(0)
36}
37
38pub fn to_cbor_bytes(obj: &impl Serialize) -> Vec<u8> {
40 let mut buf: Vec<u8> = Vec::new();
41 into_writer(obj, &mut buf).expect("failed to encode in CBOR format");
42 buf
43}