pub struct HashValue(/* private fields */);Expand description
A 32-byte cryptographic hash value.
Hash values are used throughout Aptos for:
- Transaction hashes
- State roots
- Event keys
- Merkle tree nodes
§Example
use aptos_sdk::HashValue;
// Compute a hash
let hash = HashValue::sha3_256(b"hello world");
assert_eq!(hash.to_hex().len(), 66); // "0x" + 64 hex chars
// Parse from hex (64 hex characters)
let hex = "0x0000000000000000000000000000000000000000000000000000000000000001";
let hash = HashValue::from_hex(hex).unwrap();Implementations§
Source§impl HashValue
impl HashValue
Sourcepub fn sha3_256_of<I, T>(items: I) -> Self
pub fn sha3_256_of<I, T>(items: I) -> Self
Computes the SHA3-256 hash of multiple byte slices.
Sourcepub fn from_hex<T: AsRef<[u8]>>(hex_str: T) -> AptosResult<Self>
pub fn from_hex<T: AsRef<[u8]>>(hex_str: T) -> AptosResult<Self>
Creates a hash from a hex string (with or without 0x prefix).
§Errors
Returns an error if the hex string contains invalid UTF-8, is not exactly 64 hex
characters (excluding the optional 0x prefix), or contains invalid hex characters.
Sourcepub fn from_bytes<T: AsRef<[u8]>>(bytes: T) -> AptosResult<Self>
pub fn from_bytes<T: AsRef<[u8]>>(bytes: T) -> AptosResult<Self>
Creates a hash from a byte slice.
§Errors
Returns an error if the byte slice is not exactly 32 bytes long.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for HashValue
impl<'de> Deserialize<'de> for HashValue
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Ord for HashValue
impl Ord for HashValue
Source§impl PartialOrd for HashValue
impl PartialOrd for HashValue
impl Copy for HashValue
impl Eq for HashValue
impl StructuralPartialEq for HashValue
Auto Trait Implementations§
impl Freeze for HashValue
impl RefUnwindSafe for HashValue
impl Send for HashValue
impl Sync for HashValue
impl Unpin for HashValue
impl UnwindSafe for HashValue
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoMoveArg for Twhere
T: Serialize,
impl<T> IntoMoveArg for Twhere
T: Serialize,
Source§fn into_move_arg(self) -> Result<Vec<u8>, AptosError>
fn into_move_arg(self) -> Result<Vec<u8>, AptosError>
Converts this value into BCS-encoded bytes. Read more
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToHex for T
impl<T> ToHex for T
Source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
Encode the hex strict representing
self into the result. Lower case
letters are used (e.g. f9b4ca)Source§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
Encode the hex strict representing
self into the result. Upper case
letters are used (e.g. F9B4CA)Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.