No description
Find a file
faicel 65c8bc7ade
All checks were successful
Publish crate to Forgejo registry / publish (push) Successful in 1m16s
Create Forgejo release on tag / release_on_tag (push) Successful in 1m7s
init
2026-03-06 21:33:05 +01:00
.cargo init 2026-03-06 21:33:05 +01:00
.forgejo/workflows init 2026-03-06 21:33:05 +01:00
docs init 2026-03-06 21:33:05 +01:00
src init 2026-03-06 21:33:05 +01:00
tests init 2026-03-06 21:33:05 +01:00
.gitignore init 2026-03-06 21:33:05 +01:00
Cargo.toml init 2026-03-06 21:33:05 +01:00
LICENSE init 2026-03-06 21:33:05 +01:00
README.md init 2026-03-06 21:33:05 +01:00

db_derive (HasColumns)

Rust License: MIT

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 like OpenClose).

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.