- Overview
- Features
- Installation
- Usage
- Macros
- Debugging
- Contributing
- Building The Project
- Running Tests
- Linting
- License
- Acknowledgements
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
.
- Compile-time transformations: Convert hexadecimal literals into
ObjectID
orSuiAddress
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.
To use the sui-literals
library in your Rust project, add the following to your Cargo.toml
:
[dependencies]
sui-literals = "0.1.0"
To integrate the sui-literals macros into your project, use the sui_literal!
macro to convert hexadecimal literals into ObjectID
or SuiAddress
types.
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);
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);
The sui_literal macro transforms a hexadecimal literal into either an ObjectID
or SuiAddress
based on the suffix provided.
_object
: Transforms the literal into an ObjectID
.
_address
: Transforms the literal into a SuiAddress
.
Debug prints are enabled to aid in development and troubleshooting. These prints can be seen in the console output when running your project.
Contributions are welcome! Please feel free to submit a pull request or open an issue on GitHub.
To build the project, run:
cargo build
To run the tests, execute:
cargo test
To lint the project using Clippy, run:
cargo clippy --all-targets --all-features -- -D warnings
This project is licensed under the MIT License. See the LICENSE file for more details.