Struct cosmwasm_std::Binary [−][src]
Expand description
Binary is a wrapper around Vec
This is only needed as serde-json-{core,wasm} has a horrible encoding for Vec
Tuple Fields
0: Vec<u8>
Implementations
take an (untrusted) string and decode it into bytes. fails if it is not valid base64
encode to base64 string (guaranteed to be success as we control the data inside). this returns normalized form (with trailing = if needed)
Copies content into fixed-sized array.
The result type A: ByteArray
is a workaround for
the missing const-generics.
A
is a fixed-sized array like [u8; 8]
.
ByteArray is implemented for [u8; 0]
to [u8; 64]
, such that
we are limited to 64 bytes for now.
Examples
Copy to array of explicit length
let binary = Binary::from(&[0xfb, 0x1f, 0x37]);
let array: [u8; 3] = binary.to_array().unwrap();
assert_eq!(array, [0xfb, 0x1f, 0x37]);
Copy to integer
let binary = Binary::from(&[0x8b, 0x67, 0x64, 0x84, 0xb5, 0xfb, 0x1f, 0x37]);
let num = u64::from_be_bytes(binary.to_array().unwrap());
assert_eq!(num, 10045108015024774967);
Trait Implementations
Just like Vec*binary
for us and allows us to
do &*binary
, returning a &[u8]
from a &Binary
.
With deref coercions,
this allows us to use &binary
whenever a &[u8]
is required.
Implement Binary == &[u8]
Implement std::vec::Vec<u8> == encoding::Binary
Implement &[u8] == Binary
Implement encoding::Binary == std::vec::Vec<u8>
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Serializes as a base64 string
Auto Trait Implementations
impl RefUnwindSafe for Binary
impl UnwindSafe for Binary
Blanket Implementations
Mutably borrows from an owned value. Read more