Struct cosmwasm_std::Binary[][src]

pub struct Binary(pub Vec<u8>);
Expand description

Binary is a wrapper around Vec to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Just like Vec, Binary is a smart pointer to u8. This implements *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.

The resulting type after dereferencing.

Dereferences the value.

Deserializes as a base64 string

Deserialize this value from the given Serde deserializer. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

The name of the generated JSON Schema. Read more

Generates a JSON Schema for this type. Read more

Whether JSON Schemas generated for this type should be re-used where possible using the $ref keyword. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

Implement Binary == &[u8]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Implement std::vec::Vec<u8> == encoding::Binary

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Implement &[u8] == Binary

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Implement encoding::Binary == std::vec::Vec<u8>

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Serializes as a base64 string

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.