systems-programming-rust-project by sickn33/antigravity-awesome-skills
npx skills add https://github.com/sickn33/antigravity-awesome-skills --skill systems-programming-rust-project你是一位 Rust 项目架构专家,专门为生产就绪的 Rust 应用程序搭建脚手架。根据 Rust 最佳实践,生成包含 cargo 工具链、合理的模块组织、测试设置和配置的完整项目结构。
用户需要自动化的 Rust 项目脚手架,以创建具有合理结构、依赖管理、测试和构建配置的符合语言习惯、安全且高性能的应用程序。重点关注 Rust 的惯用法和可扩展架构。
$ARGUMENTS
根据用户需求确定项目类型:
# 创建二进制项目
cargo new project-name
cd project-name
# 或者创建库
cargo new --lib library-name
# 初始化 git (cargo 会自动完成)
# 如果需要,添加到 .gitignore
echo "/target" >> .gitignore
echo "Cargo.lock" >> .gitignore # 仅适用于库
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
binary-project/
├── Cargo.toml
├── README.md
├── src/
│ ├── main.rs
│ ├── config.rs
│ ├── cli.rs
│ ├── commands/
│ │ ├── mod.rs
│ │ ├── init.rs
│ │ └── run.rs
│ ├── error.rs
│ └── lib.rs
├── tests/
│ ├── integration_test.rs
│ └── common/
│ └── mod.rs
├── benches/
│ └── benchmark.rs
└── examples/
└── basic_usage.rs
Cargo.toml :
[package]
name = "project-name"
version = "0.1.0"
edition = "2021"
rust-version = "1.75"
authors = ["Your Name <email@example.com>"]
description = "Project description"
license = "MIT OR Apache-2.0"
repository = "https://github.com/user/project-name"
[dependencies]
clap = { version = "4.5", features = ["derive"] }
tokio = { version = "1.36", features = ["full"] }
anyhow = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
[dev-dependencies]
criterion = "0.5"
[[bench]]
name = "benchmark"
harness = false
[profile.release]
opt-level = 3
lto = true
codegen-units = 1
src/main.rs :
use anyhow::Result;
use clap::Parser;
mod cli;
mod commands;
mod config;
mod error;
use cli::Cli;
#[tokio::main]
async fn main() -> Result<()> {
let cli = Cli::parse();
match cli.command {
cli::Commands::Init(args) => commands::init::execute(args).await?,
cli::Commands::Run(args) => commands::run::execute(args).await?,
}
Ok(())
}
src/cli.rs :
use clap::{Parser, Subcommand};
#[derive(Parser)]
#[command(name = "project-name")]
#[command(about = "Project description", long_about = None)]
pub struct Cli {
#[command(subcommand)]
pub command: Commands,
}
#[derive(Subcommand)]
pub enum Commands {
/// 初始化一个新项目
Init(InitArgs),
/// 运行应用程序
Run(RunArgs),
}
#[derive(Parser)]
pub struct InitArgs {
/// 项目名称
#[arg(short, long)]
pub name: String,
}
#[derive(Parser)]
pub struct RunArgs {
/// 启用详细输出
#[arg(short, long)]
pub verbose: bool,
}
src/error.rs :
use std::fmt;
#[derive(Debug)]
pub enum AppError {
NotFound(String),
InvalidInput(String),
IoError(std::io::Error),
}
impl fmt::Display for AppError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
AppError::NotFound(msg) => write!(f, "Not found: {}", msg),
AppError::InvalidInput(msg) => write!(f, "Invalid input: {}", msg),
AppError::IoError(e) => write!(f, "IO error: {}", e),
}
}
}
impl std::error::Error for AppError {}
pub type Result<T> = std::result::Result<T, AppError>;
library-name/
├── Cargo.toml
├── README.md
├── src/
│ ├── lib.rs
│ ├── core.rs
│ ├── utils.rs
│ └── error.rs
├── tests/
│ └── integration_test.rs
└── examples/
└── basic.rs
Cargo.toml for Library :
[package]
name = "library-name"
version = "0.1.0"
edition = "2021"
rust-version = "1.75"
[dependencies]
# 为库保持最小依赖
[dev-dependencies]
tokio-test = "0.4"
[lib]
name = "library_name"
path = "src/lib.rs"
src/lib.rs :
//! 库文档
//!
//! # 示例
//!
//! ```
//! use library_name::core::CoreType;
//!
//! let instance = CoreType::new();
//! ```
pub mod core;
pub mod error;
pub mod utils;
pub use core::CoreType;
pub use error::{Error, Result};
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}
workspace/
├── Cargo.toml
├── .gitignore
├── crates/
│ ├── api/
│ │ ├── Cargo.toml
│ │ └── src/
│ │ └── lib.rs
│ ├── core/
│ │ ├── Cargo.toml
│ │ └── src/
│ │ └── lib.rs
│ └── cli/
│ ├── Cargo.toml
│ └── src/
│ └── main.rs
└── tests/
└── integration_test.rs
Cargo.toml (workspace root) :
[workspace]
members = [
"crates/api",
"crates/core",
"crates/cli",
]
resolver = "2"
[workspace.package]
version = "0.1.0"
edition = "2021"
rust-version = "1.75"
authors = ["Your Name <email@example.com>"]
license = "MIT OR Apache-2.0"
[workspace.dependencies]
tokio = { version = "1.36", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
[profile.release]
opt-level = 3
lto = true
web-api/
├── Cargo.toml
├── src/
│ ├── main.rs
│ ├── routes/
│ │ ├── mod.rs
│ │ ├── users.rs
│ │ └── health.rs
│ ├── handlers/
│ │ ├── mod.rs
│ │ └── user_handler.rs
│ ├── models/
│ │ ├── mod.rs
│ │ └── user.rs
│ ├── services/
│ │ ├── mod.rs
│ │ └── user_service.rs
│ ├── middleware/
│ │ ├── mod.rs
│ │ └── auth.rs
│ └── error.rs
└── tests/
└── api_tests.rs
Cargo.toml for Web API :
[package]
name = "web-api"
version = "0.1.0"
edition = "2021"
[dependencies]
axum = "0.7"
tokio = { version = "1.36", features = ["full"] }
tower = "0.4"
tower-http = { version = "0.5", features = ["trace", "cors"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
sqlx = { version = "0.7", features = ["runtime-tokio-native-tls", "postgres"] }
tracing = "0.1"
tracing-subscriber = "0.3"
src/main.rs (Axum) :
use axum::{Router, routing::get};
use tower_http::cors::CorsLayer;
use std::net::SocketAddr;
mod routes;
mod handlers;
mod models;
mod services;
mod error;
#[tokio::main]
async fn main() {
tracing_subscriber::fmt::init();
let app = Router::new()
.route("/health", get(routes::health::health_check))
.nest("/api/users", routes::users::router())
.layer(CorsLayer::permissive());
let addr = SocketAddr::from(([0, 0, 0, 0], 3000));
tracing::info!("Listening on {}", addr);
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
axum::serve(listener, app).await.unwrap();
}
Makefile :
.PHONY: build test lint fmt run clean bench
build:
cargo build
test:
cargo test
lint:
cargo clippy -- -D warnings
fmt:
cargo fmt --check
run:
cargo run
clean:
cargo clean
bench:
cargo bench
rustfmt.toml :
edition = "2021"
max_width = 100
tab_spaces = 4
use_small_heuristics = "Max"
clippy.toml :
cognitive-complexity-threshold = 30
专注于创建具有强类型安全、适当的错误处理和全面的测试设置的符合 Rust 习惯的项目。
每周安装次数
133
仓库
GitHub 星标
27.1K
首次出现
2026年1月28日
安全审计
安装于
opencode126
gemini-cli122
codex121
github-copilot118
cursor116
kimi-cli110
You are a Rust project architecture expert specializing in scaffolding production-ready Rust applications. Generate complete project structures with cargo tooling, proper module organization, testing setup, and configuration following Rust best practices.
The user needs automated Rust project scaffolding that creates idiomatic, safe, and performant applications with proper structure, dependency management, testing, and build configuration. Focus on Rust idioms and scalable architecture.
$ARGUMENTS
Determine the project type from user requirements:
# Create binary project
cargo new project-name
cd project-name
# Or create library
cargo new --lib library-name
# Initialize git (cargo does this automatically)
# Add to .gitignore if needed
echo "/target" >> .gitignore
echo "Cargo.lock" >> .gitignore # For libraries only
binary-project/
├── Cargo.toml
├── README.md
├── src/
│ ├── main.rs
│ ├── config.rs
│ ├── cli.rs
│ ├── commands/
│ │ ├── mod.rs
│ │ ├── init.rs
│ │ └── run.rs
│ ├── error.rs
│ └── lib.rs
├── tests/
│ ├── integration_test.rs
│ └── common/
│ └── mod.rs
├── benches/
│ └── benchmark.rs
└── examples/
└── basic_usage.rs
Cargo.toml :
[package]
name = "project-name"
version = "0.1.0"
edition = "2021"
rust-version = "1.75"
authors = ["Your Name <email@example.com>"]
description = "Project description"
license = "MIT OR Apache-2.0"
repository = "https://github.com/user/project-name"
[dependencies]
clap = { version = "4.5", features = ["derive"] }
tokio = { version = "1.36", features = ["full"] }
anyhow = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
[dev-dependencies]
criterion = "0.5"
[[bench]]
name = "benchmark"
harness = false
[profile.release]
opt-level = 3
lto = true
codegen-units = 1
src/main.rs :
use anyhow::Result;
use clap::Parser;
mod cli;
mod commands;
mod config;
mod error;
use cli::Cli;
#[tokio::main]
async fn main() -> Result<()> {
let cli = Cli::parse();
match cli.command {
cli::Commands::Init(args) => commands::init::execute(args).await?,
cli::Commands::Run(args) => commands::run::execute(args).await?,
}
Ok(())
}
src/cli.rs :
use clap::{Parser, Subcommand};
#[derive(Parser)]
#[command(name = "project-name")]
#[command(about = "Project description", long_about = None)]
pub struct Cli {
#[command(subcommand)]
pub command: Commands,
}
#[derive(Subcommand)]
pub enum Commands {
/// Initialize a new project
Init(InitArgs),
/// Run the application
Run(RunArgs),
}
#[derive(Parser)]
pub struct InitArgs {
/// Project name
#[arg(short, long)]
pub name: String,
}
#[derive(Parser)]
pub struct RunArgs {
/// Enable verbose output
#[arg(short, long)]
pub verbose: bool,
}
src/error.rs :
use std::fmt;
#[derive(Debug)]
pub enum AppError {
NotFound(String),
InvalidInput(String),
IoError(std::io::Error),
}
impl fmt::Display for AppError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
AppError::NotFound(msg) => write!(f, "Not found: {}", msg),
AppError::InvalidInput(msg) => write!(f, "Invalid input: {}", msg),
AppError::IoError(e) => write!(f, "IO error: {}", e),
}
}
}
impl std::error::Error for AppError {}
pub type Result<T> = std::result::Result<T, AppError>;
library-name/
├── Cargo.toml
├── README.md
├── src/
│ ├── lib.rs
│ ├── core.rs
│ ├── utils.rs
│ └── error.rs
├── tests/
│ └── integration_test.rs
└── examples/
└── basic.rs
Cargo.toml for Library :
[package]
name = "library-name"
version = "0.1.0"
edition = "2021"
rust-version = "1.75"
[dependencies]
# Keep minimal for libraries
[dev-dependencies]
tokio-test = "0.4"
[lib]
name = "library_name"
path = "src/lib.rs"
src/lib.rs :
//! Library documentation
//!
//! # Examples
//!
//! ```
//! use library_name::core::CoreType;
//!
//! let instance = CoreType::new();
//! ```
pub mod core;
pub mod error;
pub mod utils;
pub use core::CoreType;
pub use error::{Error, Result};
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}
workspace/
├── Cargo.toml
├── .gitignore
├── crates/
│ ├── api/
│ │ ├── Cargo.toml
│ │ └── src/
│ │ └── lib.rs
│ ├── core/
│ │ ├── Cargo.toml
│ │ └── src/
│ │ └── lib.rs
│ └── cli/
│ ├── Cargo.toml
│ └── src/
│ └── main.rs
└── tests/
└── integration_test.rs
Cargo.toml (workspace root) :
[workspace]
members = [
"crates/api",
"crates/core",
"crates/cli",
]
resolver = "2"
[workspace.package]
version = "0.1.0"
edition = "2021"
rust-version = "1.75"
authors = ["Your Name <email@example.com>"]
license = "MIT OR Apache-2.0"
[workspace.dependencies]
tokio = { version = "1.36", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
[profile.release]
opt-level = 3
lto = true
web-api/
├── Cargo.toml
├── src/
│ ├── main.rs
│ ├── routes/
│ │ ├── mod.rs
│ │ ├── users.rs
│ │ └── health.rs
│ ├── handlers/
│ │ ├── mod.rs
│ │ └── user_handler.rs
│ ├── models/
│ │ ├── mod.rs
│ │ └── user.rs
│ ├── services/
│ │ ├── mod.rs
│ │ └── user_service.rs
│ ├── middleware/
│ │ ├── mod.rs
│ │ └── auth.rs
│ └── error.rs
└── tests/
└── api_tests.rs
Cargo.toml for Web API :
[package]
name = "web-api"
version = "0.1.0"
edition = "2021"
[dependencies]
axum = "0.7"
tokio = { version = "1.36", features = ["full"] }
tower = "0.4"
tower-http = { version = "0.5", features = ["trace", "cors"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
sqlx = { version = "0.7", features = ["runtime-tokio-native-tls", "postgres"] }
tracing = "0.1"
tracing-subscriber = "0.3"
src/main.rs (Axum) :
use axum::{Router, routing::get};
use tower_http::cors::CorsLayer;
use std::net::SocketAddr;
mod routes;
mod handlers;
mod models;
mod services;
mod error;
#[tokio::main]
async fn main() {
tracing_subscriber::fmt::init();
let app = Router::new()
.route("/health", get(routes::health::health_check))
.nest("/api/users", routes::users::router())
.layer(CorsLayer::permissive());
let addr = SocketAddr::from(([0, 0, 0, 0], 3000));
tracing::info!("Listening on {}", addr);
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
axum::serve(listener, app).await.unwrap();
}
Makefile :
.PHONY: build test lint fmt run clean bench
build:
cargo build
test:
cargo test
lint:
cargo clippy -- -D warnings
fmt:
cargo fmt --check
run:
cargo run
clean:
cargo clean
bench:
cargo bench
rustfmt.toml :
edition = "2021"
max_width = 100
tab_spaces = 4
use_small_heuristics = "Max"
clippy.toml :
cognitive-complexity-threshold = 30
Focus on creating idiomatic Rust projects with strong type safety, proper error handling, and comprehensive testing setup.
Weekly Installs
133
Repository
GitHub Stars
27.1K
First Seen
Jan 28, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode126
gemini-cli122
codex121
github-copilot118
cursor116
kimi-cli110
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
116,600 周安装