Skip to content

Replace hex crate with const-hex#38

Merged
gregnazario merged 5 commits intomainfrom
chore/use-const-hex
Feb 24, 2026
Merged

Replace hex crate with const-hex#38
gregnazario merged 5 commits intomainfrom
chore/use-const-hex

Conversation

@gregnazario
Copy link
Contributor

Summary

  • Replace hex crate with const-hex for hex encoding/decoding (faster, const-compatible)
  • Add serde feature to const-hex for serde deserialization helpers
  • Re-export const_hex from aptos-sdk so generated code (codegen + proc macros) works without downstream crates needing a direct const-hex dependency
  • Fix clippy needless_borrows_for_generic_args warnings

Supersedes #35

Test plan

  • cargo test -p aptos-sdk --all-features — all 875 unit tests + 31 doctests pass
  • cargo clippy -p aptos-sdk --all-features -- -D warnings — zero warnings
  • cargo fmt -- --check — clean

auterium and others added 4 commits February 24, 2026 16:11
Remove unnecessary borrows when calling const_hex::encode_prefixed
and const_hex::encode, since the arguments already implement
AsRef<[u8]>. Also add serde feature to const-hex for deserialize
support.
- Fix misleading doc comment on HashValue::from_hex that referenced
  UTF-8 validation no longer performed
- Re-export const_hex from aptos-sdk (#[doc(hidden)]) so downstream
  crates using generated code don't need a direct const-hex dependency
- Update codegen generator and proc macro to emit
  ::aptos_sdk::const_hex::encode() instead of const_hex::encode()
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates from the unmaintained hex crate to the actively maintained const-hex crate, providing faster hex encoding/decoding with const-compatible functions. The migration includes updating all hex encoding/decoding calls throughout the codebase and adding serde support for deserialization helpers.

Changes:

  • Replace hex crate dependency with const-hex (version 1.17.0 with serde feature)
  • Migrate all hex encoding from format!("0x{}", hex::encode(...)) to const_hex::encode_prefixed(...)
  • Migrate all hex decoding from manual prefix stripping + hex::decode to const_hex::decode (which handles prefixes automatically)
  • Add re-export of const_hex from aptos-sdk for generated code compatibility

Reviewed changes

Copilot reviewed 24 out of 25 changed files in this pull request and generated no comments.

Show a summary per file
File Description
Cargo.toml Replace hex dependency with const-hex version 1.17.0 with serde feature
Cargo.lock Update dependencies to include const-hex and remove hex crate
crates/aptos-sdk/CHANGELOG.md Document the migration from hex to const-hex
crates/aptos-sdk/src/lib.rs Re-export const_hex for use by generated code and proc macros
crates/aptos-sdk/src/error.rs Update error type from hex::FromHexError to const_hex::FromHexError
crates/aptos-sdk/src/types/hash.rs Simplify from_hex using const_hex::decode_to_slice, use encode_prefixed for to_hex, update documentation
crates/aptos-sdk/src/types/address.rs Use const_hex for encoding with encode_prefixed for long strings and encode for short strings
crates/aptos-sdk/src/crypto/*.rs Migrate all crypto modules to const_hex, remove manual 0x prefix stripping
crates/aptos-sdk/src/crypto/multi_*.rs Update Display/Debug formatting to use encode_prefixed, migrate serde to const_hex::deserialize
crates/aptos-sdk/src/account/*.rs Update all account types to use const_hex for hex operations
crates/aptos-sdk/src/api/fullnode.rs Use encode_prefixed for hex formatting in API calls
crates/aptos-sdk/src/codegen/generator.rs Update code generation to use ::aptos_sdk::const_hex::encode for vector types
crates/aptos-sdk-macros/src/codegen.rs Update proc macro code generation to use ::aptos_sdk::const_hex::encode
crates/aptos-sdk/tests/*.rs Update test code to use const_hex, fix needless borrow warnings
crates/aptos-sdk/examples/*.rs Update examples to use const_hex

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@gregnazario gregnazario merged commit 6e67d74 into main Feb 24, 2026
17 checks passed
@gregnazario gregnazario deleted the chore/use-const-hex branch February 24, 2026 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants