* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
line-height: 1.6;
color: #333;
background-color: #f8f9fa;
padding: 20px;
}
.container {
max-width: 1200px;
margin: 0 auto;
background: white;
padding: 40px;
border-radius: 12px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}
h1 {
color: #2c3e50;
border-bottom: 3px solid #3498db;
padding-bottom: 15px;
margin-bottom: 30px;
font-size: 2.5em;
}
h2 {
color: #34495e;
margin-top: 40px;
padding-bottom: 10px;
border-bottom: 2px solid #ecf0f1;
font-size: 1.8em;
}
h3 {
color: #7f8c8d;
margin-top: 30px;
font-size: 1.4em;
}
h4, h5, h6 {
color: #95a5a6;
margin-top: 20px;
}
p {
margin: 15px 0;
font-size: 1.1em;
line-height: 1.7;
}
ul, ol {
margin: 15px 0 15px 30px;
}
li {
margin: 8px 0;
font-size: 1.05em;
}
pre {
background: #2d3748;
color: #e2e8f0;
padding: 20px;
border-radius: 8px;
overflow-x: auto;
margin: 20px 0;
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
font-size: 0.95em;
}
code {
background: #f1f5f9;
color: #e53e3e;
padding: 2px 6px;
border-radius: 4px;
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
font-size: 0.9em;
}
pre code {
background: transparent;
color: inherit;
padding: 0;
}
a {
color: #3498db;
text-decoration: none;
transition: color 0.2s;
}
a:hover {
color: #2980b9;
text-decoration: underline;
}
blockquote {
border-left: 4px solid #3498db;
padding: 15px 20px;
margin: 20px 0;
background: #f8fafc;
font-style: italic;
color: #4a5568;
}
table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
}
th, td {
border: 1px solid #e2e8f0;
padding: 12px 15px;
text-align: left;
}
th {
background: #f7fafc;
font-weight: 600;
color: #4a5568;
}
tr:nth-child(even) {
background: #f8fafc;
}
hr {
border: none;
height: 1px;
background: #e2e8f0;
margin: 40px 0;
}
.metadata {
background: #f1f8ff;
padding: 15px;
border-radius: 8px;
margin: 20px 0;
font-size: 0.9em;
color: #586069;
}
.metadata strong {
color: #24292e;
}
.back-link {
display: inline-block;
margin-top: 30px;
padding: 10px 20px;
background: #3498db;
color: white;
border-radius: 6px;
text-decoration: none;
font-weight: 500;
transition: background 0.2s;
}
.back-link:hover {
background: #2980b9;
text-decoration: none;
}
@media (max-width: 768px) {
body {
padding: 10px;
}
.container {
padding: 20px;
}
h1 {
font-size: 2em;
}
h2 {
font-size: 1.5em;
}
h3 {
font-size: 1.2em;
}
}
/ 打印样式 /
@media print {
body {
background: white;
padding: 0;
}
.container {
box-shadow: none;
padding: 0;
}
.back-link {
display: none;
}
}
| 文档名称 | 版本 | 大小 | 制定日期 | 制定人 |
|----------|------|------|----------|--------|
| Rust (Actix-web) 编码规范 V2.0 | V2.0 | 63.7KB | - | 团队 |
| 团队Rust WASM编码规范 V1.0 | V1.0 | 16.6KB | 2026-02-28 | 林栖(cat07) |
| Rust WASM 异常处理规范(精简版) | V1.0 | 2.3KB | 2026-02-23 | 林栖(cat07) |
CatError类型,错误处理模式一致userservice, database_repo)UserService, DatabaseRepository)Trait (CatErrorServerModeTrait)getuserbyid, calculatetotalprice)username, item_count)MAXRETRYCOUNT, DEFAULT_TIMEOUT)OrderStatus::Paid, UserType::Admin)严禁使用其他编程语言的关键字或常用标识符作为Rust变量、函数或类型名:
| 语言 | 严重程度 | 示例标识符 |
|------|----------|------------|
| SQL | 严格禁止 | desc, limit, date, where, match, set, map, string等关键字 |
| Java | 严格禁止 | class, interface, public, static, String, Object等 |
| Python | 严格禁止 | async, await, def, list, dict, tuple, print等 |
| PHP | 建议避免 | echo, print_r, array, date, time等内置函数 |
| Dart | 严格禁止 | var, final, async, String, List, Map等 |
| JavaScript | 严格禁止 | function, console, window, Promise, async, await等 |
| Rust | 严格禁止 | fn, struct, trait, impl, mut, Option, Result等 |
替代策略:
user, item, data_)description 替代 desc)maximum 替代 max)desc 术语使用规范 - 示例: getuserdesc(), productdescription, orderdesc
StdDataResponse包含desc字段,Rust端应保持对应字段名一致#[wasm_bindgen]函数签名规则Result<..., JsValue>
// ❌ 错误:业务异常泄漏到JavaScript
#[wasm_bindgen]
pub fn handle_click() -> Result<(), JsValue> {
business_logic()?; // 错误会传到JavaScript
Ok(())
}
// ✅ 正确:内部处理所有错误
#[wasm_bindgen]
pub fn handle_click() {
match business_logic() {
Ok(result) => { let = JSFNS.setdataobj("result", Some(&result)); }
Err(e) => { let = JSFNS.alert(&format!("失败: {}", e)); }
}
}
JsValue(纯数据)CatError
// 第三方错误立即转换
external_lib::call()
.maperr(|e| CatError::newwith(format!("外部错误: {}", e), -5000))?;
JS_FNS自动转换
// JS_FNS调用内部已处理JavaScript异常
JSFNS.setdata_str("key", "value")?; // 内部已转CatError
JS_FNS.alert("消息")?;
JS_FNS.alert() 或状态提示JS_FNS.alert() 提供错误信息unwrap()和expect()
// ❌ 错误:可能导致panic
let value = serdewasmbindgen::to_value(&data).unwrap();
let value = vec[index]; // 直接索引可能panic
self.quit_login().expect("Quit Login Fail");
// ✅ 正确:安全访问模式
let value = vec.get(index).ok_or(CatError::new("索引越界"))?;
panic::catchunwind包装JSFNS调用JS_FNS抽象层约定JS_FNS
// ✅ 正确:通过JS_FNS抽象层
let = JSFNS.setdatastr("key", "value");
let = JSFNS.alert("消息");
let = JSFNS.setdataobj("data", Some(&data));
// ❌ 错误:直接调用JavaScript
#[wasm_bindgen]
extern "C" {
fn alert(message: &str);
}
alert("消息");
JSFNS调用忽略返回值使用let =serdewasmbindgen序列化
// 统一错误类型定义
pub type CatResult = Result;
// 错误转换实现
impl From for CatError {
fn from(err: sqlx::Error) -> Self {
match err {
sqlx::Error::RowNotFound => CatError::new("数据不存在"),
=> CatError::newwith(format!("数据库错误: {}", err), -1000),
}
}
}
// 统一响应结构
#[derive(Serialize)]
pub struct StdDataResponse {
pub code: i32,
pub data: Option,
pub desc: String, // 支持多语言的业务描述
pub timestamp: i64,
}
- 必须(MUST): 绝对要求,无例外
- 严禁(MUST NOT): 绝对禁止,无例外
- 应该(SHOULD): 强烈建议,除非有充分理由
```
[规则ID] [强度] [规则描述]
适用范围: [模块/类型]
示例:
正例: [代码示例]
反例: [代码示例]
理由: [解释原因]
```
- #[wasm_bindgen].->.Result.*JsValue
- maperr\(\\|e\\| JsValue::fromstr
- panic::catch_unwind
- \\.unwrap\( 和 \\.expect\(
- SQL关键字: desc, limit, date, where等
- Java关键字: class, interface, public等
- Python关键字: async, def, print等
- 所有错误是否转换为CatError
- 错误分支是否有用户反馈
- 第三方库错误是否转换
/root/.openclaw/workspace/delphine-ai-factory-main/docs/RustActixWeb编码规范_V2.0.md/root/.openclaw/workspace/delphine-ai-factory-main/docs/团队RustWASM编码规范V1.0.md/root/.openclaw/workspace/delphine-ai-factory-main/docs/RustWASM异常处理规范_V1.0.md总结生成: 虾酱一号(游塔极光开发团队AI助手成员)
生成时间: 2026年3月18日
数据来源: 团队Rust全栈开发代码规范三份文档
// 自动为表格添加斑马条纹
document.addEventListener('DOMContentLoaded', function() {
const tables = document.querySelectorAll('table');
tables.forEach(table => {
const rows = table.querySelectorAll('tr');
rows.forEach((row, index) => {
if (index % 2 === 1) {
row.style.backgroundColor = '#f8fafc';
}
});
});
// 为外部链接添加图标和新窗口打开
const links = document.querySelectorAll('a[href^="http"]:not([href*="' + window.location.host + '"])');
links.forEach(link => {
link.target = '_blank';
link.rel = 'noopener noreferrer';
});
// 平滑滚动到锚点
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href').substring(1);
const targetElement = document.getElementById(targetId);
if (targetElement) {
targetElement.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
});
返回