bytes32
is a type that is a 32-bit-wide byte array in Vyper. The following is from https://github.com/ethereum/vyper/blob/master/docs/types.rst#32-bit-wide-byte-array:
32-bit-wide Byte Array
Keyword: bytes32
This is a 32-bit-wide byte array that is otherwise similiar to byte arrays.
Example:
# Declaration
hash: bytes32
# Assignment
self.hash = _hash
Operators
==================================== ============================================================
Keyword Description
==================================== ============================================================
``len(x)`` Return the length as an integer.
``sha3(x)`` Return the sha3 hash as bytes32.
``concat(x, ...)`` Concatenate multiple inputs.
``slice(x, start=_start, len=_len)`` Return a slice of ``_len`` starting at ``_start``.
==================================== ============================================================
Where x
is a byte array and _start
as well as _len
are integer values.
I want to know how to create such a bytes32 as a custom type in Rust. To create custom types you use a struct, and it's an array, but I'm not sure what the best way to define the array is. I thought of doing:
struct Bytes32 {
bytes32: [0b00000000; 4]
}
But this is obviously not ideal e.g. for readability, and you have to use a specific value, 0b00000000
.