| Crates.io | midds-types-codegen |
| lib.rs | midds-types-codegen |
| version | 0.1.0 |
| created_at | 2025-07-26 23:56:05.320773+00 |
| updated_at | 2025-07-26 23:56:05.320773+00 |
| description | Procedural macros for generating types for MIDDS runtime types |
| homepage | https://allfeat.org |
| repository | https://github.com/Allfeat/allfeat-sdk |
| max_upload_size | |
| id | 1769540 |
| size | 39,764 |
Procedural macros for generating bounded string and collection types with Substrate and WebAssembly compatibility.
This crate provides macros to generate bounded types that work seamlessly with Substrate runtime and JavaScript bindings, solving wasm_bindgen's generic parameter limitations.
#[midds_string(bound)]Generates bounded string types with UTF-8 validation.
use midds_types_codegen::midds_string;
#[midds_string(256)]
pub struct TrackTitle;
// With regex validation
#[midds_string(15, regex = r"^[A-Z]{2}[A-Z0-9]{3}[0-9]{2}[0-9]{5}$")]
pub struct Isrc;
// Usage
let mut title = TrackTitle::from_str("My Song").unwrap();
title.push_str(" - Extended Mix").unwrap();
assert_eq!(title.as_str(), "My Song - Extended Mix");
#[midds_collection(type, bound)]Generates bounded collection types.
use midds_types_codegen::midds_collection;
#[midds_collection(u64, 64)]
pub struct ProducerIds;
// Usage
let mut producers = ProducerIds::new();
producers.push(12345).unwrap();
producers.push(67890).unwrap();
assert_eq!(producers.len(), 2);
Clone, PartialEq, Encode, Decode, etc.)js feature)wasm_bindgen bindingssp_runtime::BoundedVecEach generated type includes a specific error enum:
// For strings
pub enum TrackTitleError {
InvalidUtf8,
TooLong,
InvalidFormat, // If regex validation is used
}
// For collections
pub enum ProducerIdsError {
TooManyItems,
InvalidItem,
}