Skip to main content

Crate junobuild_utils

Crate junobuild_utils 

Source
Expand description

§JunoBuild-Utils

junobuild-utils provides a collection of utilities designed to support developers working on Juno, facilitating easier data handling, serialization, deserialization, and working with specialized data types.

§Getting Started

To include junobuild-utils in your Rust project, add it as a dependency in your Cargo.toml:

[dependencies]
junobuild-utils = "*"

Replace "*" with the specific version you want to use, or omit the version to always use the latest version.

§Usage Examples

§Decoding Document Data

Decode the serialized document data received by a hook.

#[derive(Deserialize)]
struct MyData {
    // Your data fields here
}

let decoded: MyData = decode_doc_data(&context.data.data.after.data).expect("Failed to decode data");

§Encoding Document Data

Encodes a Rust struct into serialized document data to prepare data to be stored.

#[derive(Serialize)]
struct MyData {
    // Your data fields here
}

let encoded = encode_doc_data(&my_data).expect("Failed to encode data");

§Handling Specialized Data Types

Work with custom data types such as DocDataPrincipal for principals and DocDataBigInt for bigint.

let principal = DocDataPrincipal { value: candid::Principal::anonymous() };
let big_int = DocDataBigInt { value: 123456789 };

Here are some useful links:

  • Looking to get started? Check out the documentation.
  • Have a look at the LICENSE for information about licensing and limitation.
  • Have questions, comments or feedback? Join our Discord or OpenChat.

Modules§

with

Structs§

JsonDataBigInt
Represents a large integer value for document data, particularly useful for interacting with languages or environments that support large numeric types, such as the bigint in JavaScript.
JsonDataNat
Represents an arbitrary precision natural number for document data, mirroring Candid’s nat type. Useful for values that exceed u64::MAX or must be compatible with Candid’s nat type.
JsonDataPrincipal
Represents a wrapper around the candid::Principal type.
JsonDataUint8Array
Represents a byte array value for document data, mirroring JavaScript’s Uint8Array.

Traits§

FromJsonData
IntoJsonData

Functions§

decode_doc_data
Decodes serialized document data into a Rust struct, tailored for use with Juno hooks.
decode_json_data
Decodes JSON data into a Rust struct.
encode_doc_data
Encodes a Rust struct into serialized document data, designed for use with Juno hooks.
encode_doc_data_to_string
Encodes a Rust struct into a JSON string, designed for use with Juno hooks.
encode_json_data
Encodes a Rust struct into JSON bytes.
encode_json_data_to_string
Encodes a Rust struct into a JSON string.

Type Aliases§

DocDataBigInt
Alias for JsonDataBigInt.
DocDataPrincipal
Alias for JsonDataPrincipal.
DocDataUint8Array
Alias for JsonDataUint8Array.