docs.rs failed to build entity-derive-impl-0.1.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build:
entity-derive-impl-0.3.0
Quick Navigation
- Getting Started: See the crate documentation above
- Derive Macro:
Entity— the main derive macro - Examples: Check the examples directory
- Wiki: Comprehensive guides
Attribute Quick Reference
Entity-Level #[entity(...)]
Field-Level Attributes
// Projections - partial views of the entity
// UserPublic struct
// UserAdmin struct
Generated Code Overview
For a User entity, the macro generates:
| Generated Type | Description |
|---|---|
CreateUserRequest |
DTO for POST requests |
UpdateUserRequest |
DTO for PATCH requests (all fields Option<T>) |
UserResponse |
DTO for API responses |
UserRow |
Database row mapping (for sqlx::FromRow) |
InsertableUser |
Struct for INSERT statements |
UserQuery |
Query struct for type-safe filtering (if #[filter] used) |
UserRepository |
Async trait with CRUD methods |
impl UserRepository for PgPool |
PostgreSQL implementation |
User{Projection} |
Projection structs (e.g., UserPublic, UserAdmin) |
From<...> impls |
Type conversions between all structs |
SQL Generation Modes
| Mode | Generates Trait | Generates Impl | Use Case |
|---|---|---|---|
sql = "full" |
✅ | ✅ | Standard CRUD, simple queries |
sql = "trait" |
✅ | ❌ | Custom SQL (joins, CTEs, search) |
sql = "none" |
❌ | ❌ | DTOs only, no database layer |
Repository Methods
The generated {Name}Repository trait includes:
Projections
Define partial views of entities for optimized SELECT queries:
// Public profile
// Admin view
// Generated: UserPublic, UserAdmin structs
// Generated: find_by_id_public, find_by_id_admin methods
// SQL: SELECT id, name, avatar FROM public.users WHERE id = $1
let public = repo.find_by_id_public.await?;
Error Handling
The generated implementation uses sqlx::Error as the error type.
You can wrap it in your application's error type:
use Entity;
// Generate trait only
// Implement with your own error type
Compile-Time Guarantees
This crate provides several compile-time guarantees:
- No sensitive data leaks: Fields marked
#[field(skip)]are excluded from all DTOs - Type-safe updates:
UpdateRequestfields are properly wrapped inOption - Consistent mapping:
Fromimpls are always in sync with field definitions - SQL injection prevention: All queries use parameterized bindings
Performance
- Zero runtime overhead: All code generation happens at compile time
- No reflection: Generated code is plain Rust structs and impls
- Minimal dependencies: Only proc-macro essentials (syn, quote, darling)
Comparison with Alternatives
| Feature | entity-derive | Diesel | SeaORM |
|---|---|---|---|
| DTO generation | ✅ | ❌ | ❌ |
| Repository pattern | ✅ | ❌ | Partial |
| Type-safe SQL | ✅ | ✅ | ✅ |
| Async support | ✅ | Partial | ✅ |
| Boilerplate reduction | ~90% | ~50% | ~60% |