Skip to content

Proc-macros to compute `SuiAddress` and `ObjectID` at compile-time.

License

Notifications You must be signed in to change notification settings

jymchng/sui-literals

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

sui-literals

πŸŽ‰ Welcome to sui-literals β€” πŸš€

Table of Contents

Overview

sui-literals is a macro library designed to transform hexadecimal literals into ObjectID or SuiAddress types at compile-time. This ensures type safety and compile-time checks for transformation suffixes, streamlining development processes in Rust projects that work with Sui blockchain addresses and object IDs.

This repository readapted the codes from uint.

Features

  • Compile-time transformations: Convert hexadecimal literals into ObjectID or SuiAddress types at compile time.
  • Error handling: Custom error types for different stages of transformation.
  • Type safety: Ensures that literals are properly formatted and suffixed.
  • Debugging: Debug prints to aid in development and troubleshooting.

Installation

To use the sui-literals library in your Rust project, add the following to your Cargo.toml:

[dependencies]
sui-literals = "0.1.0"

Usage

To integrate the sui-literals macros into your project, use the sui_literal! macro to convert hexadecimal literals into ObjectID or SuiAddress types.

Examples

Valid Usage

use sui_literals::sui_literal;

let object_id: ObjectID = sui_literal!(0x01b0d52321ce82d032430f859c6df0c52eb9ce1a337a81d56d89445db2d624f0_object);
let sui_address: SuiAddress = sui_literal!(0x01b0d52321ce82d032430f859c6df081d56d89445db2d624f0_address);

println!("{:?}", object_id);
println!("{:?}", sui_address);

Compile-Time Failures

The following example demonstrates a compile-time failure when using the sui_literal macro with an invalid suffix.

use sui_literals::sui_literal;
use sui_types::base_types::{ObjectID, SuiAddress};

let object_id = sui_literal!(0x01b0d52321ce82d032430f859c6df0c52eb9ce1a337a81d56d89445db2d624f0_invalid_suffix);

Macros

sui_literal!

The sui_literal macro transforms a hexadecimal literal into either an ObjectID or SuiAddress based on the suffix provided.

Supported Suffixes

_object: Transforms the literal into an ObjectID.

_address: Transforms the literal into a SuiAddress.

Debugging

Debug prints are enabled to aid in development and troubleshooting. These prints can be seen in the console output when running your project.

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue on GitHub.

Building the Project

To build the project, run:

cargo build

Running Tests

To run the tests, execute:

cargo test

Linting

To lint the project using Clippy, run:

cargo clippy --all-targets --all-features -- -D warnings

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Acknowledgements

About

Proc-macros to compute `SuiAddress` and `ObjectID` at compile-time.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published