pub trait AsDynSizeBytes {
// Required methods
fn as_dyn_size_bytes(&self) -> Vec<u8> ⓘ;
fn from_dyn_size_bytes(buf: &[u8]) -> Self;
}Expand description
Trait allowing encoding and decoding of unsized data.
See also SBox.
By default is implemented for:
- Every AsFixedSizeBytes type
Vec<u8>String
This trait can be easily implemented using derive macros:
- [derive::CandidAsDynSizeBytes] implements this trait for types which already implement candid::CandidType and candid::Deserialize.
- [derive::FixedSizeAsDynSizeBytes] implements this trait for types which already implement AsFixedSizeBytes.
Required Methods§
Sourcefn as_dyn_size_bytes(&self) -> Vec<u8> ⓘ
fn as_dyn_size_bytes(&self) -> Vec<u8> ⓘ
Sourcefn from_dyn_size_bytes(buf: &[u8]) -> Self
fn from_dyn_size_bytes(buf: &[u8]) -> Self
Decodes self from a slice of bytes.
§Important
The slice can have trailing bytes with unmeaningful. It means, that if your data encoded value is [1, 0, 1, 0], then it should also be able to decode itself from a slice like [1, 0, 1, 0, 0, 0, 0, 0, 0] or [1, 0, 1, 0, 1, 1, 0, 1].
§Panics
Should panic if data decoding failed.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl AsDynSizeBytes for String
Available on non-crate feature custom_dyn_encoding only.
impl AsDynSizeBytes for String
Available on non-crate feature
custom_dyn_encoding only.fn as_dyn_size_bytes(&self) -> Vec<u8> ⓘ
fn from_dyn_size_bytes(buf: &[u8]) -> Self
Source§impl AsDynSizeBytes for Vec<u8>
Available on non-crate feature custom_dyn_encoding only.
impl AsDynSizeBytes for Vec<u8>
Available on non-crate feature
custom_dyn_encoding only.fn as_dyn_size_bytes(&self) -> Vec<u8> ⓘ
fn from_dyn_size_bytes(buf: &[u8]) -> Self
Implementors§
impl<T: AsFixedSizeBytes> AsDynSizeBytes for T
Available on non-crate feature
custom_dyn_encoding only.