<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>gorust - Go 风格并发,Rust 极致性能</title>
<link href="https://fonts.googleapis.com/css2?family=Inter:opsz,wght@14..32,400;14..32,500;14..32,600;14..32,700&display=swap" rel="stylesheet">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Inter', sans-serif;
background: linear-gradient(135deg, #0a0f1e 0%, #0f172a 100%);
color: #e2e8f0;
line-height: 1.6;
}
.container {
max-width: 1280px;
margin: 0 auto;
padding: 0 2rem;
}
.navbar {
padding: 1.5rem 0;
border-bottom: 1px solid rgba(100, 116, 139, 0.2);
backdrop-filter: blur(10px);
position: sticky;
top: 0;
background: rgba(15, 23, 42, 0.8);
z-index: 10;
}
.nav-content {
display: flex;
justify-content: space-between;
align-items: center;
}
.logo {
font-size: 1.5rem;
font-weight: 700;
background: linear-gradient(135deg, #60a5fa, #a78bfa);
-webkit-background-clip: text;
background-clip: text;
color: transparent;
}
.nav-links {
display: flex;
gap: 2rem;
align-items: center;
}
.nav-links a {
color: #cbd5e1;
text-decoration: none;
font-weight: 500;
transition: color 0.2s;
}
.nav-links a:hover {
color: #60a5fa;
}
.github-link {
background: #334155;
padding: 0.5rem 1rem;
border-radius: 8px;
text-decoration: none;
color: #f1f5f9;
font-weight: 500;
transition: all 0.2s ease;
}
.github-link:hover {
background: #475569;
transform: translateY(-1px);
}
.btn {
display: inline-block;
padding: 0.75rem 1.5rem;
border-radius: 8px;
font-weight: 600;
text-decoration: none;
transition: all 0.2s ease;
cursor: pointer;
}
.btn-primary {
background: linear-gradient(135deg, #3b82f6, #8b5cf6);
color: white;
border: none;
box-shadow: 0 4px 14px 0 rgba(59,130,246,0.4);
}
.btn-primary:hover {
transform: translateY(-2px);
box-shadow: 0 6px 20px 0 rgba(59,130,246,0.6);
}
.btn-outline {
border: 1px solid #60a5fa;
color: #60a5fa;
background: transparent;
}
.btn-outline:hover {
background: rgba(96, 165, 250, 0.1);
transform: translateY(-1px);
}
.hero {
padding: 5rem 0;
text-align: center;
}
.hero h1 {
font-size: 3.5rem;
font-weight: 800;
background: linear-gradient(135deg, #fff, #94a3b8);
-webkit-background-clip: text;
background-clip: text;
color: transparent;
margin-bottom: 1rem;
}
.hero .tagline {
font-size: 1.25rem;
color: #94a3b8;
margin-bottom: 2rem;
max-width: 700px;
margin-left: auto;
margin-right: auto;
}
.badge {
background: rgba(96, 165, 250, 0.2);
border: 1px solid #3b82f6;
padding: 0.25rem 0.75rem;
border-radius: 20px;
font-size: 0.85rem;
display: inline-block;
margin-bottom: 1rem;
}
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
gap: 1.5rem;
margin: 4rem 0;
}
.stat-card {
background: rgba(30, 41, 59, 0.6);
backdrop-filter: blur(10px);
border: 1px solid rgba(100, 116, 139, 0.3);
border-radius: 16px;
padding: 1.5rem;
text-align: center;
transition: transform 0.2s;
}
.stat-card:hover {
transform: translateY(-5px);
border-color: #60a5fa;
}
.stat-number {
font-size: 2.5rem;
font-weight: 800;
color: #60a5fa;
margin-bottom: 0.5rem;
}
.stat-label {
font-size: 0.9rem;
color: #94a3b8;
text-transform: uppercase;
letter-spacing: 1px;
}
.stat-unit {
font-size: 1rem;
color: #64748b;
}
.features {
margin: 5rem 0;
}
.section-title {
font-size: 2rem;
font-weight: 700;
text-align: center;
margin-bottom: 3rem;
color: #f1f5f9;
}
.features-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 2rem;
}
.feature-card {
background: rgba(30, 41, 59, 0.4);
border-radius: 16px;
padding: 1.5rem;
border: 1px solid rgba(100, 116, 139, 0.2);
transition: all 0.2s;
}
.feature-card:hover {
border-color: #60a5fa;
transform: translateY(-3px);
}
.feature-icon {
font-size: 2rem;
margin-bottom: 1rem;
}
.feature-title {
font-size: 1.25rem;
font-weight: 600;
margin-bottom: 0.5rem;
color: #f1f5f9;
}
.code-section {
background: #0f172a;
border-radius: 16px;
padding: 2rem;
margin: 3rem 0;
border: 1px solid #334155;
}
.code-title {
font-size: 1.25rem;
font-weight: 600;
margin-bottom: 1rem;
color: #cbd5e1;
}
.example-tabs {
display: flex;
gap: 0.5rem;
margin-bottom: 1rem;
flex-wrap: wrap;
}
.tab-btn {
padding: 0.5rem 1rem;
background: #1e293b;
color: #cbd5e1;
border: 1px solid #334155;
border-radius: 8px;
cursor: pointer;
transition: all 0.2s;
font-weight: 500;
}
.tab-btn.active {
background: linear-gradient(135deg, #3b82f6, #8b5cf6);
border-color: transparent;
color: white;
}
.tab-btn:hover:not(.active) {
background: #334155;
}
.tab-content {
display: none;
}
.tab-content.active {
display: block;
}
pre {
background: #1e293b;
padding: 1.5rem;
border-radius: 8px;
overflow-x: auto;
font-size: 0.9rem;
line-height: 1.6;
}
code {
font-family: 'Monaco', 'Consolas', monospace;
color: #a5f3fc;
}
.code-block {
background: #1e293b;
border-radius: 8px;
padding: 1.5rem;
overflow-x: auto;
font-size: 0.9rem;
line-height: 1.6;
border: 1px solid #334155;
}
.code-block code {
color: #a5f3fc;
}
.code-block .comment { color: #64748b; }
.code-block .keyword { color: #c084fc; }
.code-block .string { color: #fbbf24; }
.code-block .function { color: #60a5fa; }
.code-block .type { color: #34d399; }
.code-block .macro { color: #fb923c; }
.code-block .number { color: #f472b6; }
.architecture {
margin: 5rem 0;
}
.arch-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 1.5rem;
margin-top: 2rem;
}
.arch-item {
background: rgba(30, 41, 59, 0.4);
border-radius: 16px;
padding: 1.5rem;
border: 1px solid rgba(100, 116, 139, 0.2);
border-left: 4px solid #3b82f6;
}
.arch-item h4 {
color: #60a5fa;
margin-bottom: 0.5rem;
font-size: 1.1rem;
}
.arch-item p {
color: #94a3b8;
font-size: 0.9rem;
}
.comparison-table {
width: 100%;
border-collapse: collapse;
margin: 2rem 0;
background: rgba(30, 41, 59, 0.4);
border-radius: 12px;
overflow: hidden;
}
.comparison-table th,
.comparison-table td {
padding: 1rem;
text-align: left;
border-bottom: 1px solid #334155;
}
.comparison-table th {
background: #1e293b;
font-weight: 600;
color: #cbd5e1;
}
.comparison-table tr:last-child td {
border-bottom: none;
}
.comparison-table code {
background: rgba(96, 165, 250, 0.2);
padding: 0.2rem 0.5rem;
border-radius: 4px;
font-size: 0.85rem;
}
.highlight {
color: #60a5fa;
font-weight: 600;
}
.quick-start {
margin: 3rem 0;
}
.footer {
text-align: center;
padding: 3rem 0;
border-top: 1px solid #334155;
margin-top: 4rem;
color: #64748b;
}
.footer a {
color: #60a5fa;
text-decoration: none;
}
.footer a:hover {
text-decoration: underline;
}
@media (max-width: 768px) {
.hero h1 { font-size: 2rem; }
.stat-number { font-size: 1.8rem; }
.nav-links { display: none; }
}
.fade-in {
opacity: 0;
transform: translateY(20px);
transition: opacity 0.6s, transform 0.6s;
}
.fade-in.visible {
opacity: 1;
transform: translateY(0);
}
</style>
</head>
<body>
<nav class="navbar">
<div class="container nav-content">
<div class="logo">gorust</div>
<div class="nav-links">
<a href="#features">功能</a>
<a href="#examples">示例</a>
<a href="#architecture">架构</a>
<a href="#api">API</a>
<a href="https://github.com/WLmutou/gorust" class="github-link" target="_blank">GitHub ↗</a>
</div>
</div>
</nav>
<main class="container">
<section class="hero">
<div class="badge">✨ v0.1.8 - 实验性发布</div>
<h1>gorust: <br> Go 风格并发,Rust 极致性能</h1>
<p class="tagline">
一个轻量级、高性能的并发运行时,将 Go 语言的并发模型与 Rust 的零成本抽象完美结合。
提供熟悉的 goroutines、channels 和 select 原语,让 Rust 并发编程更简单。
</p>
<div style="display: flex; gap: 1rem; justify-content: center; margin-top: 2rem;">
<a href="#quick-start" class="btn btn-primary">快速开始</a>
<a href="https://github.com/WLmutou/gorust" class="btn btn-outline">GitHub 仓库</a>
</div>
</section>
<section>
<div class="stats-grid">
<div class="stat-card fade-in">
<div class="stat-number">9+</div>
<div class="stat-label">核心模块</div>
<div class="stat-unit">channel, scheduler, timer...</div>
</div>
<div class="stat-card fade-in">
<div class="stat-number">15+</div>
<div class="stat-label">示例程序</div>
<div class="stat-unit">examples/</div>
</div>
<div class="stat-card fade-in">
<div class="stat-number">M:N</div>
<div class="stat-label">调度模型</div>
<div class="stat-unit">工作窃取算法</div>
</div>
<div class="stat-card fade-in">
<div class="stat-number">~3MB</div>
<div class="stat-label">内存占用</div>
<div class="stat-unit">基础运行时</div>
</div>
</div>
</section>
<section class="features" id="features">
<h2 class="section-title">为什么选择 gorust?</h2>
<div class="features-grid">
<div class="feature-card fade-in">
<div class="feature-icon">🚀</div>
<div class="feature-title">Goroutines</div>
<div>轻量级协程,类似 Go 的 goroutine。使用 <code>go()</code> 函数轻松创建并发任务,自动管理生命周期。</div>
</div>
<div class="feature-card fade-in">
<div class="feature-icon">📡</div>
<div class="feature-title">Channels</div>
<div>支持有缓冲和无缓冲通道,实现 goroutine 间的通信。提供 <code>send()</code> 和 <code>recv()</code> 方法。</div>
</div>
<div class="feature-card fade-in">
<div class="feature-icon">🎯</div>
<div class="feature-title">Select 宏</div>
<div>类似 Go 的 select 语句,支持多路复用通道操作。使用 <code>select!</code> 宏或函数式 API。</div>
</div>
<div class="feature-card fade-in">
<div class="feature-icon">⏱️</div>
<div class="feature-title">定时器</div>
<div>提供 <code>sleep()</code> 和 <code>sleep_ms()</code> 函数,支持协程级别的睡眠,不阻塞其他协程。</div>
</div>
<div class="feature-card fade-in">
<div class="feature-icon">🔒</div>
<div class="feature-title">同步原语</div>
<div>WaitGroup、Mutex、RWMutex、AtomicCounter、Once 等完整的同步工具集合。</div>
</div>
<div class="feature-card fade-in">
<div class="feature-icon">🌐</div>
<div class="feature-title">网络轮询器</div>
<div>基于 mio 的事件驱动网络轮询器,支持异步 I/O 操作,高效处理网络连接。</div>
</div>
<div class="feature-card fade-in">
<div class="feature-icon">📊</div>
<div class="feature-title">工作窃取调度器</div>
<div>M:N 调度模型,支持工作窃取算法,充分利用多核 CPU,自动负载均衡。</div>
</div>
<div class="feature-card fade-in">
<div class="feature-icon">🔧</div>
<div class="feature-title">过程宏</div>
<div><code>#[runtime]</code>、<code>select!</code>、<code>make_chan!</code> 等宏,提供类 Go 语法。</div>
</div>
<div class="feature-card fade-in">
<div class="feature-icon">🛡️</div>
<div class="feature-title">Ctrl-C 信号处理</div>
<div>内置信号处理,优雅关闭运行时,确保所有 goroutine 安全退出。</div>
</div>
</div>
</section>
<section class="code-section" id="examples">
<div class="code-title">📄 代码示例</div>
<div class="example-tabs">
<button class="tab-btn active" data-tab="basic">基础示例</button>
<button class="tab-btn" data-tab="channel">通道通信</button>
<button class="tab-btn" data-tab="select">Select</button>
<button class="tab-btn" data-tab="sync">同步原语</button>
</div>
<div class="tab-content active" id="basic">
<pre><code>use gorust::{go, runtime, Runtime, yield_now, sleep};
#[runtime]
fn main() {
// 创建 goroutine
go(|| {
println!("Hello from goroutine!");
});
// 带参数的 goroutine
for i in 0..5 {
go(move || {
println!("Goroutine {} is running", i);
yield_now();
println!("Goroutine {} done", i);
});
}
println!("Active goroutines: {}", Runtime::active_goroutines());
}</code></pre>
</div>
<div class="tab-content" id="channel">
<pre><code>use gorust::{go, runtime, make_chan};
#[runtime]
fn main() {
// 创建无缓冲通道
let ch = make_chan!(i32);
// 发送端
let ch_snd = ch.clone();
go(move || {
ch_snd.send(42).unwrap();
println!("Value sent!");
});
// 接收端
let ch_rcv = ch.clone();
go(move || {
let value = ch_rcv.recv().unwrap();
println!("Received: {}", value);
});
// 有缓冲通道
let ch2 = make_chan!(String, 10);
ch2.send("Hello".to_string()).unwrap();
let received = ch2.recv().unwrap();
}</code></pre>
</div>
<div class="tab-content" id="select">
<pre><code>use gorust::{go, runtime, make_chan, select, sleep};
use std::time::Duration;
#[runtime]
fn main() {
let ch1 = make_chan!(i32);
let ch2 = make_chan!(String);
// 使用 select! 宏
select! {
recv(ch1) -> msg => {
println!("Got from ch1: {:?}", msg);
}
recv(ch2) -> msg => {
println!("Got from ch2: {:?}", msg);
}
default => {
println!("No channel ready");
}
}
// 使用函数式 API
let result = select_builder()
.recv(&ch1, |msg| println!("Got: {:?}", msg))
.timeout(Duration::from_secs(2), || println!("Timeout!"))
.execute();
}</code></pre>
</div>
<div class="tab-content" id="sync">
<pre><code>use gorust::{go, runtime, sleep};
use gorust::sync::{WaitGroup, AtomicCounter};
use std::time::Duration;
#[runtime]
fn main() {
// WaitGroup 示例
let wg = WaitGroup::new();
for i in 0..3 {
wg.add(1);
let wg_clone = wg.clone();
go(move || {
println!("Task {} starting", i);
sleep(Duration::from_secs(i));
println!("Task {} finished", i);
wg_clone.done();
});
}
wg.wait();
// AtomicCounter 示例
let counter = AtomicCounter::new();
for _ in 0..100 {
let c = counter.clone();
go(move || {
c.increment();
});
}
println!("Count: {}", counter.get());
}</code></pre>
</div>
</section>
<section class="architecture" id="architecture">
<h2 class="section-title">架构设计</h2>
<div class="arch-grid">
<div class="arch-item fade-in">
<h4>调度器 (Scheduler)</h4>
<p>M:N 调度模型,多个工作线程(Processor)各自维护本地队列,支持工作窃取算法实现负载均衡。</p>
</div>
<div class="arch-item fade-in">
<h4>协程 (Goroutine)</h4>
<p>轻量级用户态协程,初始栈仅 2KB,自动栈增长。协程由调度器管理,非操作系统线程。</p>
</div>
<div class="arch-item fade-in">
<h4>通道 (Channel)</h4>
<p>支持有缓冲和无缓冲通道,内部使用环形队列实现,提供阻塞和非阻塞的 send/recv 操作。</p>
</div>
<div class="arch-item fade-in">
<h4>定时器 (Timer)</h4>
<p>分层定时器实现,基于最小堆管理超时事件,支持协程级别的 sleep 而不阻塞其他协程。</p>
</div>
<div class="arch-item fade-in">
<h4>网络轮询器 (Netpoller)</h4>
<p>基于 mio 的事件驱动 I/O 多路复用,支持 TCP/UDP 异步操作,高效处理网络连接。</p>
</div>
<div class="arch-item fade-in">
<h4>同步原语 (Sync)</h4>
<p>提供 WaitGroup、Mutex、RWMutex、Pool、Context 等 Go 风格的同步工具。</p>
</div>
</div>
</section>
<section id="api">
<h2 class="section-title">核心 API</h2>
<table class="comparison-table">
<thead>
<tr>
<th>API</th>
<th>类型</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>go(fn)</code></td>
<td>函数</td>
<td>创建新的 goroutine</td>
</tr>
<tr>
<td><code>#[runtime]</code></td>
<td>宏</td>
<td>初始化运行时并管理生命周期</td>
</tr>
<tr>
<td><code>make_chan!(T)</code></td>
<td>宏</td>
<td>创建无缓冲通道</td>
</tr>
<tr>
<td><code>make_chan!(T, cap)</code></td>
<td>宏</td>
<td>创建有缓冲通道</td>
</tr>
<tr>
<td><code>select! { ... }</code></td>
<td>宏</td>
<td>多路复用通道操作</td>
</tr>
<tr>
<td><code>sleep(duration)</code></td>
<td>函数</td>
<td>协程级睡眠</td>
</tr>
<tr>
<td><code>yield_now()</code></td>
<td>函数</td>
<td>主动让出 CPU</td>
</tr>
<tr>
<td><code>Runtime::wait_for_all()</code></td>
<td>函数</td>
<td>等待所有协程完成</td>
</tr>
</tbody>
</table>
</section>
<section class="code-section quick-start" id="quick-start">
<div class="code-title">🚀 快速开始</div>
<pre><code># 添加依赖
[dependencies]
gorust = { git = "https://github.com/WLmutou/gorust.git" }
# 创建一个简单的并发程序
cargo new my_gorust_app
cd my_gorust_app</code></pre>
<div style="margin-top: 1rem;">
<a href="https://github.com/WLmutou/gorust" class="btn btn-primary">GitHub 仓库</a>
<a href="https://docs.rs/gorust" class="btn btn-outline" style="margin-left: 1rem;">阅读文档 →</a>
</div>
</section>
<div class="footer">
<p>gorust - 开源 · 高性能 · 用 Rust 实现 Go 的并发梦想</p>
<p style="margin-top: 0.5rem;">
<a href="https://github.com/WLmutou/gorust">GitHub</a> |
<a href="https://crates.io/crates/gorust">crates.io</a> |
<a href="https://docs.rs/gorust">文档</a>
</p>
</div>
</main>
<script>
document.querySelectorAll('.tab-btn').forEach(btn => {
btn.addEventListener('click', () => {
const tabId = btn.dataset.tab;
document.querySelectorAll('.tab-btn').forEach(b => b.classList.remove('active'));
document.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active'));
btn.classList.add('active');
document.getElementById(tabId).classList.add('active');
});
});
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
}
});
}, { threshold: 0.1 });
document.querySelectorAll('.fade-in').forEach(el => observer.observe(el));
</script>
</body>
</html>