Utils
The following utilities are provided to help you work with document and asset data inside your Satellite. They simplify tasks such as decoding and encoding data, serializing custom types, and interacting with Juno’s core features in a consistent way.
All utilities on this page are provided by the junobuild-utils crate.
To use them, add this to 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.
decode_doc_data​
Deserializes raw document data (&[u8]
) into a typed Rust struct. Use this inside hooks or assertions to get the document contents in a strongly typed way.
pub fn decode_doc_data<T: for<'a> Deserialize<'a>>(
data: &[u8],
) -> Result<T, String>
📦 See full definition on docs.rs
encode_doc_data​
Serializes a Rust struct into a Vec<u8>
for storing a document into the datastore. Use this when modifying or creating document data inside a hook or assertion.
pub fn encode_doc_data<T: Serialize>(data: &T) -> Result<Vec<u8>, String>
📦 See full definition on docs.rs
encode_doc_data_to_string​
Serializes a Rust struct into a JSON String. Use this if you want to store or inspect document data in a readable format. Commonly used when exposing JSON data on the web, for example by reproducing documents from the datastore into the storage.
pub fn encode_doc_data_to_string<T: Serialize>(
data: &T,
) -> Result<String, String>
📦 See full definition on docs.rs