用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/tomevault-io/skills-registry --skill rust-conventions命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | rust-conventions |
| description | Rust coding conventions and patterns for service development. Use when this capability is needed. |
| metadata | {"author":"c9r-io"} |
These are recommended defaults; adjust to your stack.
| Component | Suggested Library |
|---|---|
| Web | axum (+ tower middleware) |
| gRPC | tonic |
| Database | sqlx |
| Async | tokio |
| Logging | tracing |
| Testing | mockall, wiremock |
src/
├── domain/ # Pure models with validation
├── service/ # Business logic (depends on repo traits)
├── repository/ # Data access (mockable traits)
├── api/ # HTTP handlers (thin)
├── grpc/ # gRPC handlers (thin)
└── cache/ # Cache facade + NoOp cache for tests (optional)
// ❌ BAD
let result = db.query().await.ok();
// ✅ GOOD - use Result with context
let result = db.query()
.await
.context("Failed to query tenant")?;
// ✅ GOOD - custom error types
#[derive(thiserror::Error, Debug)]
pub enum ServiceError {
#[error("Tenant not found: {0}")]
TenantNotFound(Uuid),
#[error("Database error: {0}")]
Database(#[from] sqlx::Error),
}
All tests run fast (~1-2s) with no Docker:
| Component | Approach |
|---|---|
| Repository | Mock traits with mockall |
| Service | Unit tests with mock repos |
| gRPC | NoOpCacheManager + mocks |
| Keycloak | wiremock HTTP mocking |
#[cfg_attr(test, mockall::automock)]
#[async_trait]
pub trait TenantRepository: Send + Sync {
async fn create(&self, input: &CreateTenantInput) -> Result<Tenant>;
async fn find_by_id(&self, id: StringUuid) -> Result<Option<Tenant>>;
}
#[cfg(test)]
mod tests {
use super::*;
use crate::repository::tenant::MockTenantRepository;
#[tokio::test]
async fn test_create_tenant() {
let mut mock = MockTenantRepository::new();
mock.expect_find_by_slug()
.returning(|_| Ok(None));
mock.expect_create()
.returning(|input| Ok(Tenant { name: input.name.clone(), ..Default::default() }));
let service = TenantService::new(Arc::new(mock), None);
let result = service.create(input).await;
assert!(result.is_ok());
}
}
use crate::cache::NoOpCacheManager;
#[tokio::test]
async fn test_exchange_token() {
let cache = NoOpCacheManager::new(); // No Redis
let service = TokenExchangeService::new(jwt_manager, cache, repos...);
// ...
}
use wiremock::{Mock, ResponseTemplate, MockServer};
#[tokio::test]
async fn test_keycloak() {
let mock_server = MockServer::start().await;
Mock::given(method("POST"))
.and(path("/realms/master/protocol/openid-connect/token"))
.respond_with(ResponseTemplate::new(200).set_body_json(json!({
"access_token": "mock-token"
})))
.mount(&mock_server).await;
// Use mock_server.uri()
}
cargo test # All tests (fast)
cargo llvm-cov --html # Coverage report
cargo clippy # Lint
cargo fmt # Format
Source: c9r-io/orchestrator — distributed by TomeVault.