aleo-std

Crates.ioaleo-std
lib.rsaleo-std
version0.1.24
sourcesrc
created_at2021-11-13 08:41:29.987739
updated_at2024-01-20 23:46:22.348982
descriptionA standard library for Aleo repositories
homepage
repository
max_upload_size
id481324
size21,737
Howard Wu (howardwu)

documentation

README

aleo-std

Crates.io Authors License

aleo-std is a standard library of tools for use in AleoHQ repositories.

Usage Guide

To use this crate to your repository, add the following to your Cargo.toml:

[dependencies.aleo-std]
version = "0.1"

CPU

fn foo() {
    // Prints the CPU name.
    println!("{:?}", aleo_std::get_cpu());
}

Storage

use aleo_std::prelude::*;

fn foo() {
    // Prints the Aleo directory.
    println!("{:?} exists: {:?}", aleo_dir(), aleo_dir().exists());
    // Prints the Aleo ledger directory in production mode.
    println!("{:?} exists: {:?}", aleo_ledger_dir(2, StorageMode::Production), aleo_ledger_dir(2, StorageMode::Production).exists());
}

Time

use aleo_std::prelude::*;

#[time]
fn foo() -> u32 {
    // Insert expensive operation
    1 + 1
}

Timed

use aleo_std::prelude::*;

#[timed]
fn foo(y: i32) -> i32 {
    let mut x = 1;
    let d = 1_000;
    x += d;
    x += y;
    x
}

#[timed]
fn main() {
    foo(23);
}

Timer

use aleo_std::prelude::*;

fn foo() -> u32 {
    // Start the timer.
    let timer = timer!("Arithmetic");

    // Insert expensive operation
    let x = 1 + 1;

    // Print the elapsed time up to this point.
    lap!(timer);

    // Insert expensive operation
    let y = 1 + 1;

    // Print the total time elapsed.
    finish!(timer);

    x + y
}
Commit count: 0

cargo fmt