Skip to main content

Gerust

Gerust logoGerust logo

Gerust is a generator for Rust backend projects. It takes care of the accidental complexity so you can stay focused on what matters.

Gerust projects build on top of axum and SQLx – proven crates that are widely used in the Rust ecosystem.

.
├── Cargo.toml
├── cli
│   └── …
├── config
│   └── …
├── db
│   └── …
├── macros
│   └── …
└── web
└── …



Separation of Concerns

Using Cargo workspaces, Gerust separates concerns clearly, improving maintainability and compile times.

web
├── src
│   ├── controllers
│   │   ├── mod.rs
│   │   └── tasks.rs
│   ├── …
│   ├── middlewares
│   │   ├── auth.rs
│   │   └── mod.rs
│   ├── routes.rs
│   ├── state.rs
│   └── …
└── tests
└── api
└── tasks_test.rs

Clear Folder Structure

A clear folder structure with defined places for different elements supports effective collaboration.

#[derive(Serialize, Debug, Deserialize)]
pub struct Task {
pub id: Uuid,
pub description: String,
}

#[derive(Deserialize, Validate, Clone)]
pub struct TaskChangeset {
#[cfg_attr(feature = "test-helpers", dummy(faker = "Sentence(3..8)"))]
#[validate(length(min = 1))]
pub description: String,
}

pub async fn load(id: Uuid, executor: impl sqlx::Executor<'_, Database = Postgres>) -> Result<Task, crate::Error> {

Complete Data Layer

Gerust comes with a complete data layer based on SQLx with entities, migrations, validations, changesets, and more.

#[db_test]
async fn test_read_all(context: &DbTestContext) {
let task_changeset: TaskChangeset = Faker.fake();
create_task(task_changeset.clone(), &context.db_pool).await.unwrap();

let response = context
.app
.request("/tasks")
.method(Method::GET)
.send()
.await;

let tasks: TasksList = response.into_body().into_json::<TasksList>().await;
assert_that!(tasks, len(eq(1)));
}

Testing

Gerust projects are fully testable with abstractions built-in for database-backed tests with complete isolation.

» cargo db migrate -e test
ℹ️ Migrating test database…
Applied migration 1732531458.
✅ 1 migrations applied.

» cargo db seed
ℹ️ Seeding development database…
✅ Seeded database successfully.







Migrations & Seed Data

Gerust generates and runs migrations and maintains seed data.

» cargo generate help
A CLI tool to generate project files.

Usage: generate [OPTIONS] <COMMAND>

Commands:
middleware Generate a middleware
controller Generate a controller
controller-test Generate a test for a controller
entity Generate an entity
crud-controller Generate an example CRUD controller
crud-controller-test Generate a test for a CRUD controller



Scaffolding

Gerust comes with tooling for generating e.g. controllers, middlewares, and entities – with scaffolding for maximum productivity.