| Crates.io | micro |
| lib.rs | micro |
| version | 0.1.14 |
| created_at | 2026-01-11 13:11:23.590605+00 |
| updated_at | 2026-01-21 15:26:24.168288+00 |
| description | Playground for macros which may result in a useful macro |
| homepage | |
| repository | https://github.com/JodusMelodus/micro |
| max_upload_size | |
| id | 2035807 |
| size | 17,017 |
micro is a lightweight Rust crate providing the FromDto procedural macro. It simplifies the conversion between Data Transfer Objects (DTOs) and your internal domain models by automatically generating From trait implementations.
Vec<T> and Option<T>, automatically calling .into() on inner items.List<T> or Response<T>) and generates appropriate trait bounds.#[from(...)] attribute.Add this to your Cargo.toml:
[dependencies]
micro = "<version>" # Update <version> to latest
If field names match, FromDto generates the boilerplate to convert from your DTO to your Domain model, calling .into() on every field to handle nested conversions.
use micro::FromDto;
// The DTO (External Source)
pub mod external {
pub struct UserDto {
pub id: i64,
pub username: String,
}
}
// The Domain Model
#[derive(FromDto)]
#[from(external::UserDto)]
pub struct User {
pub id: i64,
pub username: String,
}
The macro handles generic parameters and complex enum structures. It automatically strips generics from paths in match arms to ensure compatibility with stable Rust.
#[derive(FromDto)]
#[from(external::ApiResponse<T>)]
pub enum Response<T> {
Success(T),
Empty,
Error(ErrorWrapper),
}
FromDto detects Vec and Option types to ensure that inner types are converted correctly using the .into_iter().map(...).collect() pattern.
#[derive(FromDto)]
#[from(external::LibraryDto)]
pub struct Library {
pub tags: Vec<String>, // Handled via .collect()
pub metadata: Option<Metadata>, // Handled via .map(Into::into)
}
Converting APIs often involves deeply nested optional collections, such as Option<Vec<T>>. Since Rust's Into trait does not automatically reach through multiple layers of containers, FromDto detects these patterns and generates the necessary mapping code automatically.
#[derive(FromDto)]
#[from(external::TrackDto)]
pub struct Track {
// Generates: value.contributors.map(|v| v.into_iter().map(Into::into).collect())
pub contributors: Option<Vec<Artist>>,
}
The FromDto macro inspects your struct or enum at compile time and generates a From<Source> implementation:
split_for_impl() to ensure trait bounds like impl<T> From<Source<T>> for Target<T> are correctly declared.FromDto) and chains them using .into().