Skip to main content

Deserializable

Trait Deserializable 

pub trait Deserializable: Sized {
    // Required method
    fn read_from<R>(source: &mut R) -> Result<Self, DeserializationError>
       where R: ByteReader;

    // Provided methods
    fn min_serialized_size() -> usize { ... }
    fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError> { ... }
    fn read_from_bytes_with_budget(
        bytes: &[u8],
        budget: usize,
    ) -> Result<Self, DeserializationError> { ... }
}
Expand description

Defines how to deserialize Self from bytes.

Required Methods§

fn read_from<R>(source: &mut R) -> Result<Self, DeserializationError>
where R: ByteReader,

Reads a sequence of bytes from the provided source, attempts to deserialize these bytes into Self, and returns the result.

§Errors

Returns an error if:

  • The source does not contain enough bytes to deserialize Self.
  • Bytes read from the source do not represent a valid value for Self.

Provided Methods§

fn min_serialized_size() -> usize

Returns the minimum serialized size for one instance of this type.

This is used by ByteReader::max_alloc to estimate how many elements can be deserialized from the remaining budget, preventing denial-of-service attacks from malicious length prefixes.

The default implementation returns size_of::<Self>(), which is conservative: it may reject valid input for types where the serialized size is smaller than the in-memory size (e.g., structs with computed/cached fields that aren’t serialized).

Override this method for types where the serialized representation is smaller than the in-memory representation to allow more elements to be deserialized.

fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>

Attempts to deserialize the provided bytes into Self and returns the result.

§Errors

Returns an error if:

  • The bytes do not contain enough information to deserialize Self.
  • The bytes do not represent a valid value for Self.

Note: if bytes contains more data than needed to deserialize self, no error is returned.

fn read_from_bytes_with_budget( bytes: &[u8], budget: usize, ) -> Result<Self, DeserializationError>

Deserializes Self from bytes with a byte budget limit.

This is the recommended method for deserializing untrusted input. The budget limits how many bytes can be consumed during deserialization, preventing denial-of-service attacks that exploit length fields to cause huge allocations.

§Errors

Returns an error if:

  • The budget is exhausted before deserialization completes.
  • The bytes do not contain enough information to deserialize Self.
  • The bytes do not represent a valid value for Self.

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§

§

impl Deserializable for u8

§

impl Deserializable for u16

§

impl Deserializable for u32

§

impl Deserializable for u64

§

impl Deserializable for u128

§

impl Deserializable for ()

§

impl Deserializable for usize

§

impl Deserializable for String

§

impl Deserializable for AdviceMap

§

fn read_from<R>(source: &mut R) -> Result<AdviceMap, DeserializationError>
where R: ByteReader,

§

impl Deserializable for AsmOpId

§

fn read_from<R>(source: &mut R) -> Result<AsmOpId, DeserializationError>
where R: ByteReader,

§

impl Deserializable for Attribute

§

fn read_from<R>(source: &mut R) -> Result<Attribute, DeserializationError>
where R: ByteReader,

§

impl Deserializable for AttributeSet

§

fn read_from<R>(source: &mut R) -> Result<AttributeSet, DeserializationError>
where R: ByteReader,

§

impl Deserializable for ColumnNumber

§

fn read_from<R>(source: &mut R) -> Result<ColumnNumber, DeserializationError>
where R: ByteReader,

§

impl Deserializable for ConstantOp

§

fn read_from<R>(source: &mut R) -> Result<ConstantOp, DeserializationError>
where R: ByteReader,

§

impl Deserializable for ConstantValue

§

fn read_from<R>(source: &mut R) -> Result<ConstantValue, DeserializationError>
where R: ByteReader,

§

impl Deserializable for DebugInfo

§

fn read_from<R>(source: &mut R) -> Result<DebugInfo, DeserializationError>
where R: ByteReader,

§

impl Deserializable for DebugVarId

§

fn read_from<R>(source: &mut R) -> Result<DebugVarId, DeserializationError>
where R: ByteReader,

§

impl Deserializable for DebugVarInfo

§

fn read_from<R>(source: &mut R) -> Result<DebugVarInfo, DeserializationError>
where R: ByteReader,

§

impl Deserializable for DebugVarLocation

§

fn read_from<R>( source: &mut R, ) -> Result<DebugVarLocation, DeserializationError>
where R: ByteReader,

§

impl Deserializable for DecoratorId

§

fn read_from<R>(source: &mut R) -> Result<DecoratorId, DeserializationError>
where R: ByteReader,

§

impl Deserializable for EncryptedData

§

fn read_from<R>(source: &mut R) -> Result<EncryptedData, DeserializationError>
where R: ByteReader,

§

impl Deserializable for EncryptedData

§

fn read_from<R>(source: &mut R) -> Result<EncryptedData, DeserializationError>
where R: ByteReader,

§

impl Deserializable for EphemeralPublicKey

§

fn read_from<R>( source: &mut R, ) -> Result<EphemeralPublicKey, DeserializationError>
where R: ByteReader,

§

impl Deserializable for EphemeralPublicKey

§

fn read_from<R>( source: &mut R, ) -> Result<EphemeralPublicKey, DeserializationError>
where R: ByteReader,

§

impl Deserializable for EventId

§

fn read_from<R>(source: &mut R) -> Result<EventId, DeserializationError>
where R: ByteReader,

§

impl Deserializable for EventName

§

fn read_from<R>(source: &mut R) -> Result<EventName, DeserializationError>
where R: ByteReader,

§

impl Deserializable for ExecutionProof

§

fn read_from<R>(source: &mut R) -> Result<ExecutionProof, DeserializationError>
where R: ByteReader,

§

impl Deserializable for FileLineCol

§

fn read_from<R>(source: &mut R) -> Result<FileLineCol, DeserializationError>
where R: ByteReader,

§

impl Deserializable for Forest

§

fn read_from<R>(source: &mut R) -> Result<Forest, DeserializationError>
where R: ByteReader,

§

impl Deserializable for FunctionType

Provides [FunctionType] deserialization support via the miden-serde-utils serializer.

This is a temporary implementation to allow type information to be serialized with libraries, but in a future release we’ll either rely on the serde serialization for these types, or provide the serialization implementation in midenc-hir-type instead

§

fn read_from<R>(source: &mut R) -> Result<FunctionType, DeserializationError>
where R: ByteReader,

§

impl Deserializable for Goldilocks

§

fn read_from<R>(source: &mut R) -> Result<Goldilocks, DeserializationError>
where R: ByteReader,

§

impl Deserializable for HashFunction

§

fn read_from<R>(source: &mut R) -> Result<HashFunction, DeserializationError>
where R: ByteReader,

§

impl Deserializable for HashKind

§

fn read_from<R>(source: &mut R) -> Result<HashKind, DeserializationError>
where R: ByteReader,

§

impl Deserializable for Ident

§

fn read_from<R>(source: &mut R) -> Result<Ident, DeserializationError>
where R: ByteReader,

§

impl Deserializable for InOrderIndex

§

fn read_from<R>(source: &mut R) -> Result<InOrderIndex, DeserializationError>
where R: ByteReader,

§

impl Deserializable for IntValue

§

fn read_from<R>(source: &mut R) -> Result<IntValue, DeserializationError>
where R: ByteReader,

§

impl Deserializable for Kernel

§

fn read_from<R>(source: &mut R) -> Result<Kernel, DeserializationError>
where R: ByteReader,

§

impl Deserializable for KernelLibrary

NOTE: Serialization of libraries is likely to be deprecated in a future release

§

fn read_from<R>(source: &mut R) -> Result<KernelLibrary, DeserializationError>
where R: ByteReader,

§

impl Deserializable for Library

NOTE: Serialization of libraries is likely to be deprecated in a future release

§

fn read_from<R>(source: &mut R) -> Result<Library, DeserializationError>
where R: ByteReader,

§

impl Deserializable for LineNumber

§

fn read_from<R>(source: &mut R) -> Result<LineNumber, DeserializationError>
where R: ByteReader,

§

impl Deserializable for LineageId

Available on crate feature serde only.
§

fn read_from<R>(source: &mut R) -> Result<LineageId, DeserializationError>
where R: ByteReader,

§

impl Deserializable for MastForest

§

fn read_from<R>(source: &mut R) -> Result<MastForest, DeserializationError>
where R: ByteReader,

§

impl Deserializable for MerkleProof

§

fn read_from<R>(source: &mut R) -> Result<MerkleProof, DeserializationError>
where R: ByteReader,

§

impl Deserializable for MetaExpr

§

fn read_from<R>(source: &mut R) -> Result<MetaExpr, DeserializationError>
where R: ByteReader,

§

impl Deserializable for MetaKeyValue

§

fn read_from<R>(source: &mut R) -> Result<MetaKeyValue, DeserializationError>
where R: ByteReader,

§

impl Deserializable for MetaList

§

fn read_from<R>(source: &mut R) -> Result<MetaList, DeserializationError>
where R: ByteReader,

§

impl Deserializable for ModuleKind

§

fn read_from<R>(source: &mut R) -> Result<ModuleKind, DeserializationError>
where R: ByteReader,

§

impl Deserializable for NodeMutation

§

fn read_from<R>(source: &mut R) -> Result<NodeMutation, DeserializationError>
where R: ByteReader,

§

impl Deserializable for Nonce

§

fn read_from<R>(source: &mut R) -> Result<Nonce, DeserializationError>
where R: ByteReader,

§

impl Deserializable for Nonce

§

fn read_from<R>(source: &mut R) -> Result<Nonce, DeserializationError>
where R: ByteReader,

§

impl Deserializable for Operation

§

fn min_serialized_size() -> usize

Returns the minimum serialized size: 1 byte opcode.

Some operations have additional payload (e.g., Push has 8 bytes for Felt), but the minimum is just the opcode byte.

§

fn read_from<R>(source: &mut R) -> Result<Operation, DeserializationError>
where R: ByteReader,

§

impl Deserializable for PartialMmr

§

fn read_from<R>(source: &mut R) -> Result<PartialMmr, DeserializationError>
where R: ByteReader,

§

impl Deserializable for PartialSmt

§

fn read_from<R>(source: &mut R) -> Result<PartialSmt, DeserializationError>
where R: ByteReader,

§

impl Deserializable for PathBuf

§

fn read_from<R>(source: &mut R) -> Result<PathBuf, DeserializationError>
where R: ByteReader,

§

impl Deserializable for PrecompileRequest

§

fn read_from<R>( source: &mut R, ) -> Result<PrecompileRequest, DeserializationError>
where R: ByteReader,

§

impl Deserializable for Program

§

fn read_from<R>(source: &mut R) -> Result<Program, DeserializationError>
where R: ByteReader,

§

impl Deserializable for ProgramInfo

§

fn read_from<R>(source: &mut R) -> Result<ProgramInfo, DeserializationError>
where R: ByteReader,

§

impl Deserializable for PublicInputs

§

fn read_from<R>(source: &mut R) -> Result<PublicInputs, DeserializationError>
where R: ByteReader,

§

impl Deserializable for RandomCoin

§

fn read_from<R>(source: &mut R) -> Result<RandomCoin, DeserializationError>
where R: ByteReader,

§

impl Deserializable for RootPath

§

fn read_from<R>(source: &mut R) -> Result<RootPath, DeserializationError>
where R: ByteReader,

§

impl Deserializable for SealedMessage

§

fn read_from<R>(source: &mut R) -> Result<SealedMessage, DeserializationError>
where R: ByteReader,

§

impl Deserializable for SealingKey

§

fn read_from<R>(source: &mut R) -> Result<SealingKey, DeserializationError>
where R: ByteReader,

§

impl Deserializable for SecretKey

§

fn read_from<R>(source: &mut R) -> Result<SecretKey, DeserializationError>
where R: ByteReader,

§

impl Deserializable for SecretKey

§

fn read_from<R>(source: &mut R) -> Result<SecretKey, DeserializationError>
where R: ByteReader,

§

impl Deserializable for SmtLeaf

§

fn min_serialized_size() -> usize

Minimum serialized size: vint64 (num_entries) + u64 (leaf_index) with 0 entries.

§

fn read_from<R>(source: &mut R) -> Result<SmtLeaf, DeserializationError>
where R: ByteReader,

§

impl Deserializable for SmtProof

§

fn read_from<R>(source: &mut R) -> Result<SmtProof, DeserializationError>
where R: ByteReader,

§

impl Deserializable for SourceSpan

§

fn read_from<R>(source: &mut R) -> Result<SourceSpan, DeserializationError>
where R: ByteReader,

§

impl Deserializable for SparseMerklePath

§

fn read_from<R>( source: &mut R, ) -> Result<SparseMerklePath, DeserializationError>
where R: ByteReader,

§

impl Deserializable for StoreNode

§

fn read_from<R>(source: &mut R) -> Result<StoreNode, DeserializationError>
where R: ByteReader,

§

impl Deserializable for Type

§

fn read_from<R>(source: &mut R) -> Result<Type, DeserializationError>
where R: ByteReader,

§

impl Deserializable for UnsealingKey

§

fn read_from<R>(source: &mut R) -> Result<UnsealingKey, DeserializationError>
where R: ByteReader,

§

impl Deserializable for UntrustedMastForest

§

fn read_from<R>( source: &mut R, ) -> Result<UntrustedMastForest, DeserializationError>
where R: ByteReader,

Deserializes an [super::UntrustedMastForest] from a byte reader.

Note: This method does not apply budgeting. For untrusted input, prefer using read_from_bytes which applies budgeted deserialization.

After deserialization, callers should use [super::UntrustedMastForest::validate()] to verify structural integrity and recompute all node hashes before using the forest.

§

fn read_from_bytes( bytes: &[u8], ) -> Result<UntrustedMastForest, DeserializationError>

Deserializes an [super::UntrustedMastForest] from bytes using budgeted deserialization.

This method uses a crate::serde::BudgetedReader with a budget equal to the input size to protect against denial-of-service attacks from malicious input.

After deserialization, callers should use [super::UntrustedMastForest::validate()] to verify structural integrity and recompute all node hashes before using the forest.

§

impl Deserializable for Uri

§

fn read_from<R>(source: &mut R) -> Result<Uri, DeserializationError>
where R: ByteReader,

§

impl Deserializable for WordValue

§

fn read_from<R>(source: &mut R) -> Result<WordValue, DeserializationError>
where R: ByteReader,

§

impl<I, D> Deserializable for CsrMatrix<I, D>
where I: Idx, D: Deserializable,

§

fn min_serialized_size() -> usize

Returns the minimum serialized size for a CsrMatrix.

A CsrMatrix serializes as:

  • data_len (vint, minimum 1 byte)
  • data elements (minimum 0 if empty)
  • indptr_len (vint, minimum 1 byte)
  • indptr elements (minimum 0 if empty)

Total minimum: 2 bytes (two vint length prefixes for empty matrix)

§

fn read_from<R>(source: &mut R) -> Result<CsrMatrix<I, D>, DeserializationError>
where R: ByteReader,

§

impl<I, T> Deserializable for IndexVec<I, T>
where I: Idx, T: Deserializable,

§

fn read_from<R>(source: &mut R) -> Result<IndexVec<I, T>, DeserializationError>
where R: ByteReader,

§

impl<K, V> Deserializable for BTreeMap<K, V>

§

impl<T1> Deserializable for (T1,)
where T1: Deserializable,

§

impl<T1, T2> Deserializable for (T1, T2)

§

impl<T1, T2, T3> Deserializable for (T1, T2, T3)

§

impl<T1, T2, T3, T4> Deserializable for (T1, T2, T3, T4)

§

impl<T1, T2, T3, T4, T5> Deserializable for (T1, T2, T3, T4, T5)

§

impl<T1, T2, T3, T4, T5, T6> Deserializable for (T1, T2, T3, T4, T5, T6)

§

impl<T> Deserializable for Option<T>
where T: Deserializable,

§

fn min_serialized_size() -> usize

Returns 1 (just the bool discriminator).

The Some variant would be 1 + T::min_serialized_size(), but we use the minimum to allow more elements through the early check.

§

fn read_from<R>(source: &mut R) -> Result<Option<T>, DeserializationError>
where R: ByteReader,

§

impl<T> Deserializable for BTreeSet<T>
where T: Deserializable + Ord,

§

impl<T> Deserializable for Vec<T>
where T: Deserializable,

§

fn min_serialized_size() -> usize

Returns 1 (the minimum vint length prefix size).

The actual serialized size depends on the number of elements, which we don’t know at the point this is called. Using the minimum allows more elements through the early check; budget enforcement during actual reads provides the real protection.

§

fn read_from<R>(source: &mut R) -> Result<Vec<T>, DeserializationError>
where R: ByteReader,

§

impl<T> Deserializable for LexicographicWord<T>
where T: Into<Word> + From<Word>,

Available on not (target_family=wasm and miden).
§

fn read_from<R>( source: &mut R, ) -> Result<LexicographicWord<T>, DeserializationError>
where R: ByteReader,

§

impl<T> Deserializable for Span<T>
where T: Deserializable,

§

fn read_from<R>(source: &mut R) -> Result<Span<T>, DeserializationError>
where R: ByteReader,

§

impl<T, const C: usize> Deserializable for [T; C]
where T: Deserializable,

§

impl<const DEPTH: u8, K, V> Deserializable for MutationSet<DEPTH, K, V>

§

fn read_from<R>( source: &mut R, ) -> Result<MutationSet<DEPTH, K, V>, DeserializationError>
where R: ByteReader,

Implementors§

§

impl Deserializable for miden_test_utils::crypto::ecdsa_k256_keccak::PublicKey

§

impl Deserializable for miden_test_utils::crypto::ecdsa_k256_keccak::SecretKey

§

impl Deserializable for miden_test_utils::crypto::ecdsa_k256_keccak::Signature

§

impl Deserializable for miden_test_utils::crypto::eddsa_25519_sha512::PublicKey

§

impl Deserializable for miden_test_utils::crypto::eddsa_25519_sha512::SecretKey

§

impl Deserializable for miden_test_utils::crypto::eddsa_25519_sha512::Signature

§

impl Deserializable for miden_test_utils::crypto::falcon512_poseidon2::Nonce

§

impl Deserializable for miden_test_utils::crypto::falcon512_poseidon2::PublicKey

§

impl Deserializable for miden_test_utils::crypto::falcon512_poseidon2::SecretKey

§

impl Deserializable for miden_test_utils::crypto::falcon512_poseidon2::Signature

§

impl Deserializable for SignatureHeader

§

impl Deserializable for SignaturePoly

§

impl Deserializable for MerklePath

§

impl Deserializable for MerkleStore

§

impl Deserializable for Mmr

§

impl Deserializable for NodeIndex

§

impl Deserializable for PartialMerkleTree

§

impl Deserializable for Smt

§

impl Deserializable for AdviceInputs

§

impl Deserializable for Felt

§

impl Deserializable for StackInputs

§

impl Deserializable for StackOutputs

§

impl Deserializable for Word

Available on not (target_family=wasm and miden).
§

impl<const DEPTH: u8> Deserializable for LeafIndex<DEPTH>