Expand description
§MIDDS Types Code Generation
This crate provides procedural macros for generating bounded string and collection types that are compatible with Substrate runtime and WebAssembly bindings.
The main purpose is to solve the limitation where wasm_bindgen doesn’t support
generic parameters, preventing the use of BoundedVec<T, Bound> directly in
JavaScript-exposed APIs.
§Features
#[midds_string(bound)]: Generates bounded string types with UTF-8 validation#[midds_collection(type, bound)]: Generates bounded collection types- Substrate compatibility: Implements all required traits for runtime usage
- JavaScript bindings: Provides
wasm_bindgenintegration when thejsfeature is enabled - Type safety: Compile-time bounds checking and UTF-8 validation
- Serde support: Automatic Serialize/Deserialize implementation when the
jsfeature is enabled
§Usage
use midds_types_codegen::{midds_string, midds_collection};
// Generate a bounded string type with 256-byte limit
#[midds_string(256)]
pub struct TrackTitle;
// Generate a bounded collection type for 64 u64 values
#[midds_collection(u64, 64)]
pub struct ProducerIds;§Generated API
Each macro generates a complete API including:
- Standard trait implementations (
Clone,PartialEq,Encode,Decode, etc.) - String/collection manipulation methods
- Error handling with type-specific error enums
- JavaScript bindings (when
jsfeature is enabled)
§Architecture
The generated types wrap sp_runtime::BoundedVec to provide:
- Compile-time capacity limits
- Runtime bounds checking
- Memory-efficient storage
- Substrate runtime compatibility
Attribute Macros§
- midds_
collection - Procedural macro that generates a bounded collection type with compile-time capacity limits.
- midds_
string - Procedural macro that generates a bounded string type with compile-time capacity limits.