AssetId
AssetId
类似于Bytes32
,是对[u8; 32]
的封装,具有类似的方法,并实现了相同的特征(请参阅fuel-types documentation )。
以下是创建AssetId
的主要方法:
use std::str::FromStr;
use fuels::types::AssetId;
// Zeroed Bytes32
let asset_id = AssetId::zeroed();
// Grab the inner `[u8; 32]` from
// `Bytes32` by dereferencing (i.e. `*`) it.
assert_eq!([0u8; 32], *asset_id);
// From a `[u8; 32]`.
let my_slice = [1u8; 32];
let asset_id = AssetId::new(my_slice);
assert_eq!([1u8; 32], *asset_id);
// From a string.
let hex_str = "0x0000000000000000000000000000000000000000000000000000000000000000";
let asset_id = AssetId::from_str(hex_str)?;
assert_eq!([0u8; 32], *asset_id);