db_derive (0.1.0)
Installation
[registries.forgejo]
index = "sparse+ " # Sparse index
# index = " " # Git
[net]
git-fetch-with-cli = truecargo add db_derive@0.1.0 --registry forgejoAbout this package
Procedural macro to derive HasColumns: generates column_map() from struct field names and types
db_derive (HasColumns)
Procedural macro crate that implements the HasColumns trait for structs. It generates a column_map() function returning a mapping of field names to their Rust types.
Useful for reflection-like use cases (e.g. ORM, serialization, or schema generation) when you need to know struct field names and types at runtime.
Requirements
- Rust 1.70 or later (edition 2021)
Usage
Add the crate to your Cargo.toml (as a dependency and for the derive):
[dependencies]
db_derive = { path = "." } # or from crates.io with the published name
# Define the trait in your crate (or in a shared lib):
# trait HasColumns { fn column_map() -> std::collections::HashMap<String, String>; }
In your code:
use db_derive::HasColumns;
use std::collections::HashMap;
trait HasColumns {
fn column_map() -> HashMap<String, String>;
}
#[derive(HasColumns)]
struct User {
id: i32,
username: String,
email: String,
}
fn main() {
let columns = User::column_map();
// e.g. {"id": "i32", "username": "String", "email": "String"}
}
Limitations
- Only structs with named fields are supported (no tuple structs, no enums).
- Types in the map are the Rust type names as written (e.g.
String,i32, custom types likeOpenClose).
Deploy (Forgejo Package Registry)
To publish this crate to your Forgejo package registry (manual test), see docs/DEPLOY.md for token setup, credentials.toml, and cargo publish --registry forgejo.
Dependencies
| ID | Version |
|---|---|
| proc-macro2 | ^1.0.106 |
| quote | ^1.0.45 |
| syn | ^2.0.117 |
Details
2026-03-06 20:35:25 +00:00
Assets (1)
Versions (1)
View all
Cargo
23
Faicel <faicelbhk@gmail.com>
8 KiB
db_derive-0.1.0.crate
8 KiB
0.1.0
2026-03-06