Skip to content

Latest commit

 

History

History
76 lines (57 loc) · 1.32 KB

02-layout.md

File metadata and controls

76 lines (57 loc) · 1.32 KB

Layout

Directory structure of a common axum project:

axum-project/
├── Cargo.toml
└── src
    └── main.rs

Cargo.toml file contains dependencies. Example:

[package]
name = "axum-project"
version = "0.1.0"
edition = "2021"

[dependencies]
axum = "0.5"
tokio = { version = "1", features = ["full"] }

src/main.rs contains code. Example:

use axum::{routing::get, Router};

#[tokio::main]
async fn main() {
    let app = Router::new().route("/", get(|| async { "Hello, world!" }));

    axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
        .serve(app.into_make_service())
        .await
        .unwrap();
}

Workspace

This tutorial uses a workspace for example projects. Workspace keeps projects grouped and projects share common dependencies.

Directory structure of a workspace:

workspace/
├── Cargo.toml
├── hello-world
│   ├── Cargo.toml
│   └── src
│       └── main.rs
└── generate-random-number
    ├── Cargo.toml
    └── src
        └── main.rs

Cargo.toml in workspace contains members. Example:

[workspace]

members = [
    "hello-world",
    "generate-random-number",
]

Create a hello world application.