[{"data":1,"prerenderedAt":1797},["ShallowReactive",2],{"post-zh-claude-code-rust-new-paradigm":3},{"id":4,"title":5,"body":6,"cover":1788,"date":1789,"description":1790,"extension":1791,"meta":1792,"navigation":130,"path":1793,"seo":1794,"stem":1795,"__hash__":1796},"posts/posts/claude-code-rust-new-paradigm.md","Claude Code + Rust：当 AI 遇上最严格的编译器",{"type":7,"value":8,"toc":1767},"minimark",[9,13,17,40,46,49,56,60,65,68,180,187,259,276,287,291,294,385,392,415,422,426,429,586,593,607,611,614,675,678,706,709,840,864,868,872,875,1119,1128,1153,1157,1160,1171,1178,1182,1186,1189,1196,1199,1235,1242,1246,1249,1271,1278,1329,1343,1347,1350,1353,1584,1589,1600,1605,1619,1624,1638,1645,1649,1652,1678,1689,1692,1695,1735,1738,1741,1744,1751,1754,1761,1764],[10,11,12],"h2",{"id":12},"一个反直觉的发现",[14,15,16],"p",{},"用 AI 写代码，选什么语言最高效？",[14,18,19,20,27,28,33,34,39],{},"直觉会说 Python。语法简单、AI 训练数据多、生成即运行。但在过去几个月用 ",[21,22,26],"a",{"href":23,"rel":24},"https://docs.anthropic.com/en/docs/claude-code",[25],"nofollow","Claude Code"," 开发了 ",[21,29,32],{"href":30,"rel":31},"https://github.com/madeye/https_proxy",[25],"https_proxy"," 和 ",[21,35,38],{"href":36,"rel":37},"https://github.com/madeye/trans_proxy",[25],"trans_proxy"," 两个 Rust 项目之后，我的结论正好相反：",[14,41,42],{},[43,44,45],"strong",{},"Rust 可能是最适合 AI 编程的语言。",[14,47,48],{},"不是因为 AI 写 Rust 从不犯错。它犯的错不少。而是因为 Rust 的编译器会在毫秒级内把错误精确地拍回来，形成一个极其高效的反馈循环。Python 代码生成后\"看起来对了\"，但 bug 可能藏在运行时的某个角落；Rust 代码只要编译通过，一大类错误就已经被消灭了。",[14,50,51,52,55],{},"这篇文章以这两个项目的实际开发经历为线索，讨论为什么 ",[43,53,54],{},"Claude Code + Rust"," 会成为一种更好的编程范式。",[10,57,59],{"id":58},"编译器是-ai-最好的搭档","编译器是 AI 最好的搭档",[61,62,64],"h3",{"id":63},"类型系统自动验证-ai-的输出","类型系统：自动验证 AI 的输出",[14,66,67],{},"先看 trans_proxy 中上游代理协议的定义：",[69,70,75],"pre",{"className":71,"code":72,"language":73,"meta":74,"style":74},"language-rust shiki shiki-themes github-light github-dark","enum ProxyProtocol {\n    HttpConnect,\n    Socks5(ProxyAuth),\n}\n\nenum ProxyAuth {\n    None,\n    UsernamePassword { username: String, password: String },\n}\n","rust","",[76,77,78,95,104,119,125,132,142,150,175],"code",{"__ignoreMap":74},[79,80,83,87,91],"span",{"class":81,"line":82},"line",1,[79,84,86],{"class":85},"szBVR","enum",[79,88,90],{"class":89},"sScJk"," ProxyProtocol",[79,92,94],{"class":93},"sVt8B"," {\n",[79,96,98,101],{"class":81,"line":97},2,[79,99,100],{"class":89},"    HttpConnect",[79,102,103],{"class":93},",\n",[79,105,107,110,113,116],{"class":81,"line":106},3,[79,108,109],{"class":89},"    Socks5",[79,111,112],{"class":93},"(",[79,114,115],{"class":89},"ProxyAuth",[79,117,118],{"class":93},"),\n",[79,120,122],{"class":81,"line":121},4,[79,123,124],{"class":93},"}\n",[79,126,128],{"class":81,"line":127},5,[79,129,131],{"emptyLinePlaceholder":130},true,"\n",[79,133,135,137,140],{"class":81,"line":134},6,[79,136,86],{"class":85},[79,138,139],{"class":89}," ProxyAuth",[79,141,94],{"class":93},[79,143,145,148],{"class":81,"line":144},7,[79,146,147],{"class":89},"    None",[79,149,103],{"class":93},[79,151,153,156,159,162,165,168,170,172],{"class":81,"line":152},8,[79,154,155],{"class":89},"    UsernamePassword",[79,157,158],{"class":93}," { username",[79,160,161],{"class":85},":",[79,163,164],{"class":89}," String",[79,166,167],{"class":93},", password",[79,169,161],{"class":85},[79,171,164],{"class":89},[79,173,174],{"class":93}," },\n",[79,176,178],{"class":81,"line":177},9,[79,179,124],{"class":93},[14,181,182,183,186],{},"当 AI 生成处理上游连接的代码时，它必须覆盖 ",[76,184,185],{},"ProxyProtocol"," 的每个变体：",[69,188,190],{"className":71,"code":189,"language":73,"meta":74,"style":74},"match &proxy.protocol {\n    ProxyProtocol::HttpConnect => { /* HTTP CONNECT 隧道 */ }\n    ProxyProtocol::Socks5(auth) => { /* SOCKS5 握手 */ }\n}\n",[76,191,192,209,233,255],{"__ignoreMap":74},[79,193,194,197,200,203,206],{"class":81,"line":82},[79,195,196],{"class":85},"match",[79,198,199],{"class":85}," &",[79,201,202],{"class":93},"proxy",[79,204,205],{"class":85},".",[79,207,208],{"class":93},"protocol {\n",[79,210,211,214,217,220,223,226,230],{"class":81,"line":97},[79,212,213],{"class":89},"    ProxyProtocol",[79,215,216],{"class":85},"::",[79,218,219],{"class":89},"HttpConnect",[79,221,222],{"class":85}," =>",[79,224,225],{"class":93}," { ",[79,227,229],{"class":228},"sJ8bj","/* HTTP CONNECT 隧道 */",[79,231,232],{"class":93}," }\n",[79,234,235,237,239,242,245,248,250,253],{"class":81,"line":106},[79,236,213],{"class":89},[79,238,216],{"class":85},[79,240,241],{"class":89},"Socks5",[79,243,244],{"class":93},"(auth) ",[79,246,247],{"class":85},"=>",[79,249,225],{"class":93},[79,251,252],{"class":228},"/* SOCKS5 握手 */",[79,254,232],{"class":93},[79,256,257],{"class":81,"line":121},[79,258,124],{"class":93},[14,260,261,262,264,265,267,268,271,272,275],{},"如果 AI 遗漏了 ",[76,263,241],{}," 分支，或者在 ",[76,266,241],{}," 里忘记处理 ",[76,269,270],{},"UsernamePassword"," 认证。编译器直接报错，连运行的机会都没有。这不是 lint 警告，不是 best practice 建议，是",[43,273,274],{},"硬性编译失败","。",[14,277,278,279,282,283,286],{},"在 Python 中，同样的逻辑可能写成一串 ",[76,280,281],{},"if/elif","，遗漏一个分支只会在运行时某个特定条件下触发 ",[76,284,285],{},"KeyError","。AI 不会告诉你它漏了什么，因为它自己也不知道。",[61,288,290],{"id":289},"borrow-checker并发安全的自动证明","Borrow Checker：并发安全的自动证明",[14,292,293],{},"trans_proxy 的 DNS 模块大量使用跨任务共享状态：",[69,295,297],{"className":71,"code":296,"language":73,"meta":74,"style":74},"// DNS 查询表：IP → 域名的映射\nlet dns_table: Arc\u003CRwLock\u003CHashMap\u003CIpv4Addr, String>>> = ...;\n\n// 查询合并器：避免重复请求\nlet coalescer: Arc\u003CQueryCoalescer> = ...;\n",[76,298,299,304,351,355,360],{"__ignoreMap":74},[79,300,301],{"class":81,"line":82},[79,302,303],{"class":228},"// DNS 查询表：IP → 域名的映射\n",[79,305,306,309,312,314,317,320,323,325,328,330,333,336,339,342,345,348],{"class":81,"line":97},[79,307,308],{"class":85},"let",[79,310,311],{"class":93}," dns_table",[79,313,161],{"class":85},[79,315,316],{"class":89}," Arc",[79,318,319],{"class":93},"\u003C",[79,321,322],{"class":89},"RwLock",[79,324,319],{"class":93},[79,326,327],{"class":89},"HashMap",[79,329,319],{"class":93},[79,331,332],{"class":89},"Ipv4Addr",[79,334,335],{"class":93},", ",[79,337,338],{"class":89},"String",[79,340,341],{"class":93},">>> ",[79,343,344],{"class":85},"=",[79,346,347],{"class":85}," ...",[79,349,350],{"class":93},";\n",[79,352,353],{"class":81,"line":106},[79,354,131],{"emptyLinePlaceholder":130},[79,356,357],{"class":81,"line":121},[79,358,359],{"class":228},"// 查询合并器：避免重复请求\n",[79,361,362,364,367,369,371,373,376,379,381,383],{"class":81,"line":127},[79,363,308],{"class":85},[79,365,366],{"class":93}," coalescer",[79,368,161],{"class":85},[79,370,316],{"class":89},[79,372,319],{"class":93},[79,374,375],{"class":89},"QueryCoalescer",[79,377,378],{"class":93},"> ",[79,380,344],{"class":85},[79,382,347],{"class":85},[79,384,350],{"class":93},[14,386,387,388,391],{},"AI 生成的异步代码经常涉及跨 ",[76,389,390],{},"tokio::spawn"," 边界的数据共享。在 Go 或 Python 中，数据竞争是运行时的偶发事件，可能在压力测试中才偶尔浮现。在 Rust 中：",[393,394,395,403,408],"ul",{},[396,397,398,399,402],"li",{},"忘记 ",[76,400,401],{},"Arc"," 包装？编译失败。所有权无法跨线程转移",[396,404,398,405,407],{},[76,406,322],{},"？编译失败。不能在多线程中可变借用",[396,409,410,411,414],{},"在持有锁的情况下 ",[76,412,413],{},".await","？Clippy 直接警告死锁风险",[14,416,417,418,421],{},"Borrow checker 把\"代码审查中需要人类凭经验发现的并发 bug\"变成了\"编译器自动检测的类型错误\"。对于 AI 生成的代码，这意味着",[43,419,420],{},"无需信任 AI 的并发推理能力","。编译器会替你验证。",[61,423,425],{"id":424},"穷举-match消灭遗漏","穷举 Match：消灭遗漏",[14,427,428],{},"https_proxy 的隐身检测是一个典型例子：",[69,430,432],{"className":71,"code":431,"language":73,"meta":74,"style":74},"pub fn is_proxy_request(req: &Request\u003CIncoming>) -> bool {\n    if req.method() == Method::CONNECT {\n        return true;\n    }\n    if req.version() == Version::HTTP_2 {\n        return false;\n    }\n    req.uri().authority().is_some()\n}\n",[76,433,434,471,501,511,516,541,550,554,582],{"__ignoreMap":74},[79,435,436,439,442,445,448,450,452,455,457,460,463,466,469],{"class":81,"line":82},[79,437,438],{"class":85},"pub",[79,440,441],{"class":85}," fn",[79,443,444],{"class":89}," is_proxy_request",[79,446,447],{"class":93},"(req",[79,449,161],{"class":85},[79,451,199],{"class":85},[79,453,454],{"class":89},"Request",[79,456,319],{"class":93},[79,458,459],{"class":89},"Incoming",[79,461,462],{"class":93},">) ",[79,464,465],{"class":85},"->",[79,467,468],{"class":89}," bool",[79,470,94],{"class":93},[79,472,473,476,479,481,484,487,490,493,495,499],{"class":81,"line":97},[79,474,475],{"class":85},"    if",[79,477,478],{"class":93}," req",[79,480,205],{"class":85},[79,482,483],{"class":89},"method",[79,485,486],{"class":93},"() ",[79,488,489],{"class":85},"==",[79,491,492],{"class":89}," Method",[79,494,216],{"class":85},[79,496,498],{"class":497},"sj4cs","CONNECT",[79,500,94],{"class":93},[79,502,503,506,509],{"class":81,"line":106},[79,504,505],{"class":85},"        return",[79,507,508],{"class":497}," true",[79,510,350],{"class":93},[79,512,513],{"class":81,"line":121},[79,514,515],{"class":93},"    }\n",[79,517,518,520,522,524,527,529,531,534,536,539],{"class":81,"line":127},[79,519,475],{"class":85},[79,521,478],{"class":93},[79,523,205],{"class":85},[79,525,526],{"class":89},"version",[79,528,486],{"class":93},[79,530,489],{"class":85},[79,532,533],{"class":89}," Version",[79,535,216],{"class":85},[79,537,538],{"class":497},"HTTP_2",[79,540,94],{"class":93},[79,542,543,545,548],{"class":81,"line":134},[79,544,505],{"class":85},[79,546,547],{"class":497}," false",[79,549,350],{"class":93},[79,551,552],{"class":81,"line":144},[79,553,515],{"class":93},[79,555,556,559,561,564,567,569,572,574,576,579],{"class":81,"line":152},[79,557,558],{"class":93},"    req",[79,560,205],{"class":85},[79,562,563],{"class":89},"uri",[79,565,566],{"class":93},"()",[79,568,205],{"class":85},[79,570,571],{"class":89},"authority",[79,573,566],{"class":93},[79,575,205],{"class":85},[79,577,578],{"class":89},"is_some",[79,580,581],{"class":93},"()\n",[79,583,584],{"class":81,"line":177},[79,585,124],{"class":93},[14,587,588,589,592],{},"这段逻辑看似简单，但背后的判断链条非常精确：CONNECT 一定是代理请求；HTTP/2 非 CONNECT 一定不是（因为 ",[76,590,591],{},":authority"," 伪头始终存在）；HTTP/1.x 看 URI 是否包含 authority。",[14,594,595,596,599,600,603,604,606],{},"当 AI 生成这类分支逻辑时，Rust 的穷举 match 确保了每个 ",[76,597,598],{},"Method","、每个 ",[76,601,602],{},"Version"," 变体都被考虑到。如果未来 hyper 库新增了 HTTP/3 的 ",[76,605,602],{}," 变体，所有未覆盖的 match 会自动变成编译错误，而不是静默地走进一个错误的 fallback 分支。",[10,608,610],{"id":609},"互补关系ai-擅长什么rust-补足什么","互补关系：AI 擅长什么，Rust 补足什么",[14,612,613],{},"AI 和 Rust 编译器各自有明显的强项和弱项，恰好形成互补：",[615,616,617,632],"table",{},[618,619,620],"thead",{},[621,622,623,626,629],"tr",{},[624,625],"th",{},[624,627,628],{},"AI 擅长",[624,630,631],{},"AI 不擅长",[633,634,635,649,662],"tbody",{},[621,636,637,643,646],{},[638,639,640],"td",{},[43,641,642],{},"模式识别",[638,644,645],{},"见过数百万个 HTTP 解析器实现，生成新的得心应手",[638,647,648],{},"判断某个特定实现在边界条件下是否正确",[621,650,651,656,659],{},[638,652,653],{},[43,654,655],{},"API 记忆",[638,657,658],{},"精确记忆 tokio、hyper、reqwest 的 API 签名和用法",[638,660,661],{},"确保 API 调用的顺序和组合在所有执行路径上都正确",[621,663,664,669,672],{},[638,665,666],{},[43,667,668],{},"样板代码",[638,670,671],{},"秒级生成 serde 序列化、clap 参数定义、错误类型转换",[638,673,674],{},"保证生成的类型定义在整个项目中一致",[14,676,677],{},"Rust 编译器精确地补上了右列的每一项：",[393,679,680,694,700],{},[396,681,682,685,686,689,690,693],{},[43,683,684],{},"边界条件","：",[76,687,688],{},"Option\u003CT>"," 强制处理空值，",[76,691,692],{},"Result\u003CT, E>"," 强制处理错误",[396,695,696,699],{},[43,697,698],{},"执行路径","：穷举 match 确保所有分支被覆盖",[396,701,702,705],{},[43,703,704],{},"全局一致性","：类型系统确保修改一处接口后，所有调用方都必须适配",[14,707,708],{},"以 https_proxy 的配置系统为例。AI 生成了完整的配置结构体：",[69,710,712],{"className":71,"code":711,"language":73,"meta":74,"style":74},"#[derive(Debug, Deserialize, Serialize, Clone)]\nstruct Config {\n    listen: String,\n    domain: String,\n    acme: AcmeConfig,\n    users: Vec\u003CUserConfig>,\n    #[serde(default)]\n    stealth: StealthConfig,\n    #[serde(default)]\n    fast_open: bool,\n}\n",[76,713,714,740,750,761,772,784,802,807,819,823,835],{"__ignoreMap":74},[79,715,716,719,722,724,727,729,732,734,737],{"class":81,"line":82},[79,717,718],{"class":93},"#[derive(",[79,720,721],{"class":89},"Debug",[79,723,335],{"class":93},[79,725,726],{"class":89},"Deserialize",[79,728,335],{"class":93},[79,730,731],{"class":89},"Serialize",[79,733,335],{"class":93},[79,735,736],{"class":89},"Clone",[79,738,739],{"class":93},")]\n",[79,741,742,745,748],{"class":81,"line":97},[79,743,744],{"class":85},"struct",[79,746,747],{"class":89}," Config",[79,749,94],{"class":93},[79,751,752,755,757,759],{"class":81,"line":106},[79,753,754],{"class":93},"    listen",[79,756,161],{"class":85},[79,758,164],{"class":89},[79,760,103],{"class":93},[79,762,763,766,768,770],{"class":81,"line":121},[79,764,765],{"class":93},"    domain",[79,767,161],{"class":85},[79,769,164],{"class":89},[79,771,103],{"class":93},[79,773,774,777,779,782],{"class":81,"line":127},[79,775,776],{"class":93},"    acme",[79,778,161],{"class":85},[79,780,781],{"class":89}," AcmeConfig",[79,783,103],{"class":93},[79,785,786,789,791,794,796,799],{"class":81,"line":134},[79,787,788],{"class":93},"    users",[79,790,161],{"class":85},[79,792,793],{"class":89}," Vec",[79,795,319],{"class":93},[79,797,798],{"class":89},"UserConfig",[79,800,801],{"class":93},">,\n",[79,803,804],{"class":81,"line":144},[79,805,806],{"class":93},"    #[serde(default)]\n",[79,808,809,812,814,817],{"class":81,"line":152},[79,810,811],{"class":93},"    stealth",[79,813,161],{"class":85},[79,815,816],{"class":89}," StealthConfig",[79,818,103],{"class":93},[79,820,821],{"class":81,"line":177},[79,822,806],{"class":93},[79,824,826,829,831,833],{"class":81,"line":825},10,[79,827,828],{"class":93},"    fast_open",[79,830,161],{"class":85},[79,832,468],{"class":89},[79,834,103],{"class":93},[79,836,838],{"class":81,"line":837},11,[79,839,124],{"class":93},[14,841,842,33,845,848,849,852,853,856,857,860,861,863],{},[76,843,844],{},"#[derive(Deserialize)]",[76,846,847],{},"#[serde(default)]"," 这类注解，AI 比大多数人都记得准。但如果 AI 在某处把 ",[76,850,851],{},"users"," 的类型从 ",[76,854,855],{},"Vec\u003CUserConfig>"," 改成了 ",[76,858,859],{},"HashMap\u003CString, String>","，所有使用 ",[76,862,851],{}," 的代码会立即编译失败。不需要人去全局搜索哪里用了这个字段。",[10,865,867],{"id":866},"效率杠杆秒级反馈循环","效率杠杆：秒级反馈循环",[61,869,871],{"id":870},"cargo-check-的魔力","cargo check 的魔力",[14,873,874],{},"下图对比了两种反馈循环的差异：",[876,877,881,882,881,886,881,915,923,881,881,928,881,881,881,935,881,945,881,881,952,881,881,959,881,964,881,970,881,881,976,881,983,881,881,991,881,995,881,1000,881,881,1005,881,881,1010,881,1014,881,881,1019,881,1023,881,881,1030,881,1039,881,881,881,1045,881,1049,881,881,1052,881,881,1055,881,1059,881,1064,881,881,1068,881,1073,881,881,1079,881,1083,881,1087,881,881,1091,881,881,1094,881,1097,881,881,1101,881,1105,881,881,1111,881,1115],"svg",{"viewBox":878,"xmlns":879,"style":880},"0 0 780 340","http://www.w3.org/2000/svg","max-width:780px;width:100%;height:auto;margin:1.5em auto;display:block","\n  ",[883,884,885],"style",{},"\n    text{font-family:system-ui,-apple-system,sans-serif;fill:#1e293b}\n    .fl-title{font-size:14px;font-weight:700;text-anchor:middle}\n    .fl-label{font-size:12px;text-anchor:middle;dominant-baseline:central;font-weight:600}\n    .fl-sub{font-size:10px;text-anchor:middle;dominant-baseline:central;fill:#64748b}\n    .fl-edge{font-size:10px;fill:#64748b;text-anchor:middle}\n    .fl-box{rx:6;ry:6;stroke-width:1.5}\n    .fl-blue{fill:#eff6ff;stroke:#3b82f6} .fl-c-blue{fill:#1d4ed8}\n    .fl-amber{fill:#fffbeb;stroke:#f59e0b} .fl-c-amber{fill:#b45309}\n    .fl-red{fill:#fef2f2;stroke:#ef4444} .fl-c-red{fill:#dc2626}\n    .fl-green{fill:#f0fdf4;stroke:#22c55e} .fl-c-green{fill:#15803d}\n    .fl-purple{fill:#faf5ff;stroke:#a855f7} .fl-c-purple{fill:#7e22ce}\n    .fl-gray{fill:#f8fafc;stroke:#94a3b8} .fl-c-gray{fill:#475569}\n    .fl-line{stroke:#94a3b8;stroke-width:1.5;fill:none}\n    .fl-line-slow{stroke:#ef4444;stroke-width:1.5;fill:none}\n    .fl-line-fast{stroke:#22c55e;stroke-width:1.5;fill:none}\n    .fl-badge{font-size:10px;font-weight:700;text-anchor:middle;dominant-baseline:central}\n    .fl-divider{stroke:#e2e8f0;stroke-width:1;stroke-dasharray:6,4}\n    [data-theme=\"dark\"] text{fill:#e2e8f0}\n    [data-theme=\"dark\"] .fl-sub{fill:#94a3b8}\n    [data-theme=\"dark\"] .fl-edge{fill:#94a3b8}\n    [data-theme=\"dark\"] .fl-blue{fill:#1e3a5f;stroke:#3b82f6} [data-theme=\"dark\"] .fl-c-blue{fill:#60a5fa}\n    [data-theme=\"dark\"] .fl-amber{fill:#422006;stroke:#f59e0b} [data-theme=\"dark\"] .fl-c-amber{fill:#fbbf24}\n    [data-theme=\"dark\"] .fl-red{fill:#450a0a;stroke:#ef4444} [data-theme=\"dark\"] .fl-c-red{fill:#f87171}\n    [data-theme=\"dark\"] .fl-green{fill:#052e16;stroke:#22c55e} [data-theme=\"dark\"] .fl-c-green{fill:#4ade80}\n    [data-theme=\"dark\"] .fl-purple{fill:#2e1065;stroke:#a855f7} [data-theme=\"dark\"] .fl-c-purple{fill:#c084fc}\n    [data-theme=\"dark\"] .fl-gray{fill:#1e293b;stroke:#475569} [data-theme=\"dark\"] .fl-c-gray{fill:#94a3b8}\n    [data-theme=\"dark\"] .fl-line{stroke:#475569}\n    [data-theme=\"dark\"] .fl-line-slow{stroke:#f87171}\n    [data-theme=\"dark\"] .fl-line-fast{stroke:#4ade80}\n    [data-theme=\"dark\"] .fl-divider{stroke:#334155}\n  ",[887,888,889,890,889,903,889,909,881],"defs",{},"\n    ",[891,892,898],"marker",{"id":893,"markerWidth":894,"markerHeight":895,"refX":894,"refY":896,"orient":897},"fl-ah","7","5","2.5","auto",[899,900],"path",{"d":901,"fill":902},"M0,0 L7,2.5 L0,5Z","#94a3b8",[891,904,906],{"id":905,"markerWidth":894,"markerHeight":895,"refX":894,"refY":896,"orient":897},"fl-ah-r",[899,907],{"d":901,"fill":908},"#ef4444",[891,910,912],{"id":911,"markerWidth":894,"markerHeight":895,"refX":894,"refY":896,"orient":897},"fl-ah-g",[899,913],{"d":901,"fill":914},"#22c55e",[916,917,922],"text",{"x":918,"y":919,"className":920},"200","24",[921],"fl-title","\n传统工作流\n",[916,924,927],{"x":925,"y":919,"className":926},"590",[921],"\nClaude Code + Rust 工作流\n",[81,929],{"x1":930,"y1":931,"x2":930,"y2":932,"className":933},"390","10","330",[934],"fl-divider",[936,937],"rect",{"x":938,"y":939,"width":940,"height":941,"className":942},"120","50","160","40",[943,944],"fl-box","fl-blue",[916,946,951],{"x":918,"y":947,"className":948},"70",[949,950],"fl-label","fl-c-blue","AI 生成代码",[81,953],{"x1":918,"y1":954,"x2":918,"y2":955,"className":956,"markerEnd":958},"90","112",[957],"fl-line","url(#fl-ah)",[936,960],{"x":938,"y":961,"width":940,"height":941,"className":962},"115",[943,963],"fl-amber",[916,965,969],{"x":918,"y":966,"className":967},"129",[949,968],"fl-c-amber","人阅读代码",[916,971,975],{"x":918,"y":972,"className":973},"144",[974],"fl-sub","理解、评估、查找问题",[81,977],{"x1":918,"y1":978,"x2":918,"y2":979,"className":980,"markerEnd":982},"155","177",[981],"fl-line-slow","url(#fl-ah-r)",[916,984,990],{"x":985,"y":986,"className":987},"226","170",[988,989],"fl-edge","fl-c-red","分钟级",[936,992],{"x":938,"y":993,"width":940,"height":941,"className":994},"180",[943,963],[916,996,999],{"x":918,"y":997,"className":998},"194",[949,968],"人描述问题",[916,1001,1004],{"x":918,"y":1002,"className":1003},"209",[974],"用自然语言反馈给 AI",[81,1006],{"x1":918,"y1":1007,"x2":918,"y2":1008,"className":1009,"markerEnd":982},"220","242",[981],[936,1011],{"x":938,"y":1012,"width":940,"height":941,"className":1013},"245",[943,944],[916,1015,1018],{"x":918,"y":1016,"className":1017},"265",[949,950],"AI 修改代码",[899,1020],{"d":1021,"className":1022,"markerEnd":982},"M120,265 L60,265 L60,70 L115,70",[981],[916,1024,1029],{"x":1025,"y":986,"className":1026,"transform":1028},"48",[1027,989],"fl-badge","rotate(-90,48,170)","人工循环",[936,1031],{"x":1032,"y":1033,"width":1034,"height":1035,"rx":1036,"fill":1037,"stroke":908,"strokeWidth":1038},"130","300","140","26","13","#fef2f2","1",[916,1040,1044],{"x":918,"y":1041,"className":1042,"style":1043},"313",[1027,989],"font-size:11px","⏱ 每轮 3~10 分钟",[936,1046],{"x":1047,"y":939,"width":940,"height":941,"className":1048},"510",[943,944],[916,1050,951],{"x":925,"y":947,"className":1051},[949,950],[81,1053],{"x1":925,"y1":954,"x2":925,"y2":955,"className":1054,"markerEnd":958},[957],[936,1056],{"x":1047,"y":961,"width":940,"height":941,"className":1057},[943,1058],"fl-purple",[916,1060,1063],{"x":925,"y":966,"className":1061},[949,1062],"fl-c-purple","cargo check",[916,1065,1067],{"x":925,"y":972,"className":1066},[974],"类型 · 所有权 · 生命周期",[81,1069],{"x1":925,"y1":978,"x2":925,"y2":979,"className":1070,"markerEnd":1072},[1071],"fl-line-fast","url(#fl-ah-g)",[916,1074,1078],{"x":1075,"y":986,"className":1076},"616",[988,1077],"fl-c-green","秒级",[936,1080],{"x":1047,"y":993,"width":940,"height":941,"className":1081},[943,1082],"fl-green",[916,1084,1086],{"x":925,"y":997,"className":1085},[949,1077],"精确错误信息",[916,1088,1090],{"x":925,"y":1002,"className":1089},[974],"文件、行号、修复建议",[81,1092],{"x1":925,"y1":1007,"x2":925,"y2":1008,"className":1093,"markerEnd":1072},[1071],[936,1095],{"x":1047,"y":1012,"width":940,"height":941,"className":1096},[943,944],[916,1098,1100],{"x":925,"y":1016,"className":1099},[949,950],"AI 自动修复",[899,1102],{"d":1103,"className":1104,"markerEnd":1072},"M510,265 L450,265 L450,70 L505,70",[1071],[916,1106,1110],{"x":1107,"y":986,"className":1108,"transform":1109},"438",[1027,1077],"rotate(-90,438,170)","自动循环",[936,1112],{"x":1113,"y":1033,"width":1034,"height":1035,"rx":1036,"fill":1114,"stroke":914,"strokeWidth":1038},"520","#f0fdf4",[916,1116,1118],{"x":925,"y":1041,"className":1117,"style":1043},[1027,1077],"⏱ 每轮 3~10 秒",[14,1120,1121,1122,1124,1125,275],{},"左侧的传统工作流中，人是瓶颈。阅读、理解、评估一段代码可能需要几分钟。右侧的 Rust 工作流中，",[76,1123,1063],{}," 秒级完成类型检查，Claude Code 直接读取编译器输出并自动修复，",[43,1126,1127],{},"整个循环不需要人的介入",[14,1129,1130,1131,1134,1135,1138,1139,1142,1143,1145,1146,1149,1150],{},"一个典型场景：开发 trans_proxy 的 SOCKS5 支持时，AI 第一轮生成的代码在 ",[76,1132,1133],{},"ProxyAuth::UsernamePassword"," 分支中忘记了对 ",[76,1136,1137],{},"username"," 长度做 ",[76,1140,1141],{},"u8"," 范围检查（SOCKS5 RFC 1929 要求用户名不超过 255 字节）。",[76,1144,1063],{}," 通过了，但 ",[76,1147,1148],{},"cargo test"," 中的边界测试捕获了问题。AI 看到测试输出后，第二轮就生成了正确的验证逻辑。",[43,1151,1152],{},"从错误到修复，整个循环不到 30 秒。",[61,1154,1156],{"id":1155},"对比动态语言的反馈延迟","对比：动态语言的反馈延迟",[14,1158,1159],{},"如果同样的项目用 Python 写：",[393,1161,1162,1165,1168],{},[396,1163,1164],{},"类型错误？要等运行时触发，或者依赖 mypy（覆盖率通常不到 100%）",[396,1166,1167],{},"并发 bug？可能在压力测试中偶现，难以稳定复现",[396,1169,1170],{},"API 不匹配？import 成功不代表调用正确，要等实际执行到那一行",[14,1172,1173,1174,1177],{},"这些延迟的反馈意味着 AI 的错误可能一路传播到后面的代码中，修复成本指数级增长。Rust 的编译器把尽可能多的验证前移到编译期，让 AI 的每一轮迭代都从一个",[43,1175,1176],{},"已验证的基线","出发。",[10,1179,1181],{"id":1180},"实战案例两个项目的开发历程","实战案例：两个项目的开发历程",[61,1183,1185],{"id":1184},"https_proxy10-个模块的协作","https_proxy：10 个模块的协作",[14,1187,1188],{},"https_proxy 的代码组织成 10 个模块：",[69,1190,1194],{"className":1191,"code":1193,"language":916},[1192],"language-text","src/\n├── main.rs      # 入口与 CLI\n├── config.rs    # YAML 配置解析\n├── tls.rs       # ACME 证书与 TLS\n├── stealth.rs   # 隐身伪装检测\n├── auth.rs      # Basic Auth 认证\n├── proxy.rs     # CONNECT 隧道与 HTTP 转发\n├── net.rs       # TCP 连接与 Fast Open\n├── service.rs   # hyper 服务层\n├── setup.rs     # TUI 配置向导\n└── lib.rs       # 模块导出\n",[76,1195,1193],{"__ignoreMap":74},[14,1197,1198],{},"这个结构不是一开始就设计好的。开发过程大致是：",[1200,1201,1202,1208,1214,1220,1229],"ol",{},[396,1203,1204,1207],{},[43,1205,1206],{},"我描述需求","（What）：\"我需要一个 HTTPS 正向代理，支持 ACME 自动证书、隐身伪装、多用户认证\"",[396,1209,1210,1213],{},[43,1211,1212],{},"AI 生成初始代码","（How）：根据需求生成模块结构和核心逻辑",[396,1215,1216,1219],{},[43,1217,1218],{},"编译器反馈","（Correctness）：类型不匹配、生命周期错误、未处理的 Result。逐一修复",[396,1221,1222,1225,1226,1228],{},[43,1223,1224],{},"我补充约束","（Why）：\"隐身检测需要区分 HTTP/1.1 和 HTTP/2，因为 HTTP/2 的 ",[76,1227,591],{}," 语义不同\"",[396,1230,1231,1234],{},[43,1232,1233],{},"迭代收敛","：AI 修改 → 编译 → 测试 → 反馈 → AI 修改",[14,1236,1237,1238,1241],{},"整个过程中，",[43,1239,1240],{},"我几乎不写具体的 Rust 代码","。我的工作是定义需求、解释领域知识、评审架构决策。AI 负责把这些意图转化为类型安全的实现。编译器确保实现不会偏离类型系统定义的契约。",[61,1243,1245],{"id":1244},"trans_proxy系统编程的挑战","trans_proxy：系统编程的挑战",[14,1247,1248],{},"trans_proxy 更有挑战性，因为它涉及大量平台相关的系统编程：",[393,1250,1251,1258,1265,1268],{},[396,1252,1253,1254,1257],{},"macOS 上通过 ",[76,1255,1256],{},"DIOCNATLOOK"," ioctl 查询 pf NAT 表",[396,1259,1260,1261,1264],{},"Linux 上通过 ",[76,1262,1263],{},"SO_ORIGINAL_DST"," getsockopt 获取原始目的地址",[396,1266,1267],{},"DNS 协议的二进制解析（手动字节操作）",[396,1269,1270],{},"SOCKS5 三步握手的状态机",[14,1272,1273,1274,1277],{},"这些场景下，AI 的 API 记忆能力体现得很明显。",[76,1275,1276],{},"ioctl"," 的参数结构、socket option 的常量值、DNS 报文的偏移量，这些细节 AI 比人记得准。而 Rust 的类型系统确保了：",[69,1279,1281],{"className":71,"code":1280,"language":73,"meta":74,"style":74},"// DNS 查询合并：broadcast channel 的类型签名\n// 确保发送端和接收端传递的数据类型一致\nlet (tx, _) = broadcast::channel::\u003CVec\u003Cu8>>(1);\n",[76,1282,1283,1288,1293],{"__ignoreMap":74},[79,1284,1285],{"class":81,"line":82},[79,1286,1287],{"class":228},"// DNS 查询合并：broadcast channel 的类型签名\n",[79,1289,1290],{"class":81,"line":97},[79,1291,1292],{"class":228},"// 确保发送端和接收端传递的数据类型一致\n",[79,1294,1295,1297,1300,1302,1305,1307,1310,1312,1314,1317,1319,1321,1324,1326],{"class":81,"line":106},[79,1296,308],{"class":85},[79,1298,1299],{"class":93}," (tx, _) ",[79,1301,344],{"class":85},[79,1303,1304],{"class":89}," broadcast",[79,1306,216],{"class":85},[79,1308,1309],{"class":89},"channel",[79,1311,216],{"class":85},[79,1313,319],{"class":93},[79,1315,1316],{"class":89},"Vec",[79,1318,319],{"class":93},[79,1320,1141],{"class":89},[79,1322,1323],{"class":93},">>(",[79,1325,1038],{"class":497},[79,1327,1328],{"class":93},");\n",[14,1330,1331,1332,1335,1336,1335,1339,1342],{},"AI 生成的 DNS 线格式解析器（",[76,1333,1334],{},"parse_query_name","、",[76,1337,1338],{},"parse_a_records",[76,1340,1341],{},"extract_min_ttl","）使用了大量的字节索引操作。这类代码容易出现 off-by-one 错误，但 Rust 的数组边界检查在运行时会 panic 而不是静默越界。即使编译器没能在编译期捕获，运行时也不会产生内存安全问题。",[10,1344,1346],{"id":1345},"新范式人ai编译器的三角分工","新范式：人、AI、编译器的三角分工",[14,1348,1349],{},"传统编程是人对着编辑器，把脑中的逻辑翻译成代码。AI 编程助手出现后，很多人的使用方式是\"AI 写初稿，人来改\"。实际上还是人在做 Correctness 验证。",[14,1351,1352],{},"Claude Code + Rust 打开了一种不同的分工模式：",[876,1354,881,1357,881,1360,881,881,1377,881,1385,881,1393,881,1401,881,1408,881,1413,881,1418,881,1423,881,1428,881,1433,881,881,1438,881,1443,881,1449,881,1454,881,1459,881,1463,881,1467,881,1472,881,1477,881,1482,881,881,1487,881,1492,881,1498,881,1503,881,1508,881,1512,881,1516,881,1520,881,1524,881,881,1528,881,1534,881,881,1540,881,1545,881,881,1550,881,1556,881,881,1561,881,1565,881,1569,1576,1580],{"viewBox":1355,"xmlns":879,"style":1356},"0 0 760 320","max-width:760px;width:100%;height:auto;margin:1.5em auto;display:block",[883,1358,1359],{},"\n    text{font-family:system-ui,-apple-system,sans-serif;fill:#1e293b}\n    .tr-title{font-size:16px;font-weight:700;text-anchor:middle;dominant-baseline:central}\n    .tr-role{font-size:13px;text-anchor:middle;dominant-baseline:central;font-weight:600}\n    .tr-item{font-size:11px;text-anchor:start;dominant-baseline:central;fill:#64748b}\n    .tr-edge{font-size:11px;text-anchor:middle;dominant-baseline:central;font-weight:600}\n    .tr-box{rx:10;ry:10;stroke-width:2}\n    .tr-amber{fill:#fffbeb;stroke:#f59e0b} .tr-c-amber{fill:#b45309}\n    .tr-blue{fill:#eff6ff;stroke:#3b82f6} .tr-c-blue{fill:#1d4ed8}\n    .tr-green{fill:#f0fdf4;stroke:#22c55e} .tr-c-green{fill:#15803d}\n    .tr-line{stroke:#475569;stroke-width:2;fill:none}\n    .tr-line-ret{stroke:#94a3b8;stroke-width:1.5;fill:none;stroke-dasharray:6,3}\n    .tr-dot{font-size:11px;fill:#64748b}\n    [data-theme=\"dark\"] text{fill:#e2e8f0}\n    [data-theme=\"dark\"] .tr-item{fill:#94a3b8}\n    [data-theme=\"dark\"] .tr-amber{fill:#422006;stroke:#f59e0b} [data-theme=\"dark\"] .tr-c-amber{fill:#fbbf24}\n    [data-theme=\"dark\"] .tr-blue{fill:#1e3a5f;stroke:#3b82f6} [data-theme=\"dark\"] .tr-c-blue{fill:#60a5fa}\n    [data-theme=\"dark\"] .tr-green{fill:#052e16;stroke:#22c55e} [data-theme=\"dark\"] .tr-c-green{fill:#4ade80}\n    [data-theme=\"dark\"] .tr-line{stroke:#94a3b8}\n    [data-theme=\"dark\"] .tr-line-ret{stroke:#475569}\n    [data-theme=\"dark\"] .tr-dot{fill:#94a3b8}\n  ",[887,1361,889,1362,889,1372,881],{},[891,1363,1368],{"id":1364,"markerWidth":1365,"markerHeight":1366,"refX":1365,"refY":1367,"orient":897},"tr-ah","8","6","3",[899,1369],{"d":1370,"fill":1371},"M0,0 L8,3 L0,6Z","#475569",[891,1373,1375],{"id":1374,"markerWidth":1365,"markerHeight":1366,"refX":1365,"refY":1367,"orient":897},"tr-ah-ret",[899,1376],{"d":1370,"fill":902},[936,1378],{"x":1379,"y":941,"width":1380,"height":1381,"className":1382},"30","190","240",[1383,1384],"tr-box","tr-amber",[916,1386,1392],{"x":1387,"y":1388,"className":1389},"125","72",[1390,1391],"tr-title","tr-c-amber","人",[916,1394,1400],{"x":1395,"y":1396,"className":1397,"textAnchor":1399},"55","105",[1398,1391],"tr-role","start","What — 定义需求",[916,1402,1407],{"x":1403,"y":1404,"className":1405},"65","128",[1406],"tr-item","• 透明代理，拦截网关流量",[916,1409,1412],{"x":1403,"y":1410,"className":1411},"148",[1406],"• 隐身 HTTPS 正向代理",[916,1414,1417],{"x":1403,"y":1415,"className":1416},"168",[1406],"• 多用户认证",[916,1419,1422],{"x":1395,"y":1420,"className":1421,"textAnchor":1399},"198",[1398,1391],"Why — 解释约束",[916,1424,1427],{"x":1403,"y":1425,"className":1426},"221",[1406],"• HTTP/2 的 :authority 语义",[916,1429,1432],{"x":1403,"y":1430,"className":1431},"241",[1406],"• DNS 污染需要 DoH",[916,1434,1437],{"x":1403,"y":1435,"className":1436},"261",[1406],"• SOCKS5 RFC 合规",[936,1439],{"x":1440,"y":941,"width":1380,"height":1381,"className":1441},"285",[1383,1442],"tr-blue",[916,1444,1448],{"x":1445,"y":1388,"className":1446},"380",[1390,1447],"tr-c-blue","AI",[916,1450,1453],{"x":1451,"y":1396,"className":1452,"textAnchor":1399},"310",[1398,1447],"How — 实现代码",[916,1455,1458],{"x":1456,"y":1404,"className":1457},"320",[1406],"• tokio 异步服务器",[916,1460,1462],{"x":1456,"y":1410,"className":1461},[1406],"• SOCKS5 握手状态机",[916,1464,1466],{"x":1456,"y":1415,"className":1465},[1406],"• DNS 报文解析器",[916,1468,1471],{"x":1456,"y":1469,"className":1470},"188",[1406],"• ACME 证书签发",[916,1473,1476],{"x":1456,"y":1474,"className":1475},"208",[1406],"• pf / nftables 集成",[916,1478,1481],{"x":1456,"y":1479,"className":1480},"228",[1406],"• serde 配置序列化",[916,1483,1486],{"x":1456,"y":1484,"className":1485},"248",[1406],"• 平台条件编译",[936,1488],{"x":1489,"y":941,"width":1380,"height":1381,"className":1490},"540",[1383,1491],"tr-green",[916,1493,1497],{"x":1494,"y":1388,"className":1495},"635",[1390,1496],"tr-c-green","编译器",[916,1499,1502],{"x":1500,"y":1396,"className":1501,"textAnchor":1399},"565",[1398,1496],"Correctness — 验证",[916,1504,1507],{"x":1505,"y":1404,"className":1506},"575",[1406],"• 类型系统验证契约",[916,1509,1511],{"x":1505,"y":1410,"className":1510},[1406],"• Borrow checker 并发安全",[916,1513,1515],{"x":1505,"y":1415,"className":1514},[1406],"• 穷举 match 无遗漏",[916,1517,1519],{"x":1505,"y":1469,"className":1518},[1406],"• 生命周期无悬垂引用",[916,1521,1523],{"x":1505,"y":1474,"className":1522},[1406],"• Option/Result 强制处理",[916,1525,1527],{"x":1505,"y":1479,"className":1526},[1406],"• Send/Sync 线程安全",[81,1529],{"x1":1007,"y1":1032,"x2":1530,"y2":1032,"className":1531,"markerEnd":1533},"280",[1532],"tr-line","url(#tr-ah)",[916,1535,1539],{"x":1536,"y":938,"className":1537},"250",[1538,1391],"tr-edge","需求",[81,1541],{"x1":1542,"y1":1032,"x2":1543,"y2":1032,"className":1544,"markerEnd":1533},"475","535",[1532],[916,1546,1549],{"x":1547,"y":938,"className":1548},"505",[1538,1447],"代码",[899,1551],{"d":1552,"className":1553,"markerEnd":1555},"M535,190 L475,190",[1554],"tr-line-ret","url(#tr-ah-ret)",[916,1557,1560],{"x":1547,"y":1474,"className":1558,"style":1559},[1538],"fill:#64748b","错误",[899,1562],{"d":1563,"className":1564,"markerEnd":1555},"M280,190 L220,190",[1554],[916,1566,1568],{"x":1536,"y":1474,"className":1567,"style":1559},[1538],"交付",[916,1570,1575],{"x":1387,"y":1571,"className":1572,"textAnchor":1574},"305",[1573],"tr-dot","middle","\n高层决策（低频）\n",[916,1577,1579],{"x":1445,"y":1571,"className":1578,"textAnchor":1574},[1573],"\n代码生成（高频）\n",[916,1581,1583],{"x":1494,"y":1571,"className":1582,"textAnchor":1574},[1573],"\n自动验证（每次）\n",[14,1585,1586,685],{},[43,1587,1588],{},"人负责 What 和 Why",[393,1590,1591,1594,1597],{},[396,1592,1593],{},"\"我需要一个透明代理，拦截网关流量通过上游 CONNECT 代理转发\"",[396,1595,1596],{},"\"DNS 要支持 DoH，因为传统 UDP 有污染风险\"",[396,1598,1599],{},"\"隐身检测要区分 HTTP 版本，因为 HTTP/2 的语义不同\"",[14,1601,1602,685],{},[43,1603,1604],{},"AI 负责 How",[393,1606,1607,1610,1613,1616],{},[396,1608,1609],{},"生成 tokio 异步服务器骨架",[396,1611,1612],{},"实现 SOCKS5 握手状态机",[396,1614,1615],{},"编写 DNS 报文解析器",[396,1617,1618],{},"处理平台差异的条件编译",[14,1620,1621,685],{},[43,1622,1623],{},"编译器负责 Correctness",[393,1625,1626,1629,1632,1635],{},[396,1627,1628],{},"类型系统验证接口契约",[396,1630,1631],{},"Borrow checker 证明并发安全",[396,1633,1634],{},"穷举 match 消灭遗漏分支",[396,1636,1637],{},"生命周期检查防止悬垂引用",[14,1639,1640,1641,1644],{},"这种三角分工之所以高效，关键在于",[43,1642,1643],{},"反馈循环是自动化的","。AI 生成代码后不需要等人来检查类型是否正确、并发是否安全。编译器秒级给出答案。人只需要在更高的抽象层面参与：需求对不对？架构合不合理？领域逻辑有没有遗漏？",[10,1646,1648],{"id":1647},"不只是-rust","不只是 Rust",[14,1650,1651],{},"这种范式并非 Rust 独有。任何有强类型系统和严格编译期检查的语言都能受益：",[393,1653,1654,1660,1666,1672],{},[396,1655,1656,1659],{},[43,1657,1658],{},"Haskell","：更强的类型系统，但生态和 AI 训练数据较少",[396,1661,1662,1665],{},[43,1663,1664],{},"OCaml","：优秀的类型推断，但社区较小",[396,1667,1668,1671],{},[43,1669,1670],{},"TypeScript（strict 模式）","：类型系统弱于 Rust，但在前端领域实用",[396,1673,1674,1677],{},[43,1675,1676],{},"Swift","：值类型和可选类型提供了类似的安全保证",[14,1679,1680,1681,1684,1685,1688],{},"Rust 之所以特别适合，是因为它在",[43,1682,1683],{},"类型安全的严格程度","和",[43,1686,1687],{},"实际生态的丰富度","之间取得了最好的平衡。tokio、hyper、serde、clap 这些库的质量和文档都是一流的，AI 的训练数据也相当充分。",[10,1690,1691],{"id":1691},"局限与诚实的反思",[14,1693,1694],{},"这种范式不是万能的：",[1200,1696,1697,1703,1712,1725],{},[396,1698,1699,1702],{},[43,1700,1701],{},"学习曲线仍然存在","。人需要理解 Rust 的所有权模型才能有效评审 AI 的代码。如果你完全不懂 Rust，编译器的错误信息对你也是天书。",[396,1704,1705,275,1708,1711],{},[43,1706,1707],{},"编译器不检查业务逻辑",[76,1709,1710],{},"is_proxy_request"," 的三条判断规则是否正确覆盖了 HTTP 语义？这需要人的领域知识。编译器只保证代码\"类型正确\"，不保证\"逻辑正确\"。",[396,1713,1714,1717,1718,1720,1721,1724],{},[43,1715,1716],{},"编译速度是代价","。虽然 ",[76,1719,1063],{}," 很快，但完整的 ",[76,1722,1723],{},"cargo build --release","（特别是开启 LTO 时）可能需要几分钟。这是类型安全的税。",[396,1726,1727,1730,1731,1734],{},[43,1728,1729],{},"不是所有项目都需要 Rust","。一次性脚本、数据分析、快速原型。Python 仍然是更合适的选择。这种范式最适合需要",[43,1732,1733],{},"长期维护、性能敏感、并发密集","的系统级项目。",[10,1736,1737],{"id":1737},"小结",[14,1739,1740],{},"回到开头的问题：用 AI 写代码，选什么语言最高效？",[14,1742,1743],{},"如果目标是\"最快生成看起来能跑的代码\"，Python 赢。",[14,1745,1746,1747,1750],{},"如果目标是\"最快生成",[43,1748,1749],{},"正确的","代码\"，Rust 赢。",[14,1752,1753],{},"因为在 Rust 的世界里，AI 不是独自工作的。编译器在它身边，不遗漏任何类型错误、任何未处理的边界、任何不安全的并发访问。",[14,1755,1756,1757,1760],{},"https_proxy 和 trans_proxy 的开发体验让我确信：",[43,1758,1759],{},"Claude Code + Rust 重新定义了人、AI 和工具之间的分工","。人专注于最有价值的判断（定义 What 和 Why），AI 承担最繁重的劳动（实现 How），编译器提供最可靠的保障（验证 Correctness）。",[14,1762,1763],{},"这就是我当前在用 AI 编程的方式。",[883,1765,1766],{},"html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}",{"title":74,"searchDepth":97,"depth":97,"links":1768},[1769,1770,1775,1776,1780,1784,1785,1786,1787],{"id":12,"depth":97,"text":12},{"id":58,"depth":97,"text":59,"children":1771},[1772,1773,1774],{"id":63,"depth":106,"text":64},{"id":289,"depth":106,"text":290},{"id":424,"depth":106,"text":425},{"id":609,"depth":97,"text":610},{"id":866,"depth":97,"text":867,"children":1777},[1778,1779],{"id":870,"depth":106,"text":871},{"id":1155,"depth":106,"text":1156},{"id":1180,"depth":97,"text":1181,"children":1781},[1782,1783],{"id":1184,"depth":106,"text":1185},{"id":1244,"depth":106,"text":1245},{"id":1345,"depth":97,"text":1346},{"id":1647,"depth":97,"text":1648},{"id":1691,"depth":97,"text":1691},{"id":1737,"depth":97,"text":1737},"/assets/covers/claude-code-rust-new-paradigm.jpg","2026-03-18T00:00:00.000Z","以 https_proxy 和 trans_proxy 两个 Rust 项目的开发实践为例，探讨 AI 编程助手与强类型编译器如何构成新的编程范式。人负责 What 和 Why，AI 负责 How，编译器负责 Correctness。","md",{},"/posts/claude-code-rust-new-paradigm",{"title":5,"description":1790},"posts/claude-code-rust-new-paradigm","ttzCb-aXIZEszn39jfVXWRUgBOTStzP_r0S_BoYGgGg",1788681981391]