大名鼎鼎的 The Algorithms 的 Rust 版本,使用 Rust 实现所有算法。
GitHub 地址:TheAlgorithms/Rust: All Algorithms implemented in Rust
GitHub 地址:ekzhang/rustpad: Efficient and minimal collaborative code editor, self-hosted, no database required
fn main() {
let text = "textwrap: an efficient and powerful library for wrapping text.";
println!("{}", textwrap::fill(text, 28));
}
// output
textwrap: an efficient
and powerful library for
wrapping text.GitHub 地址:mgeisler/textwrap: An efficient and powerful Rust library for word wrapping text.
GitHub 地址:fosskers/linya: Simple concurrent progress bars.
GitHub 地址:nathom/youchoose: A lightweight terminal menu for Rust
仅使用 tokio 实现的简单聊天服务器:
use tokio::{
io::{AsyncBufReadExt, AsyncWriteExt, BufReader},
net::TcpListener,
sync::broadcast,
};
#[tokio::main]
async fn main() {
let listener = TcpListener::bind("localhost:8080").await.unwrap();
let (tx, _rx) = broadcast::channel(10);
loop {
let (mut socket, addr) = listener.accept().await.unwrap();
let tx = tx.clone();
let mut rx = tx.subscribe();
tokio::spawn(async move {
let (reader, mut writer) = socket.split();
let mut reader = BufReader::new(reader);
let mut line = String::new();
loop {
tokio::select! {
result = reader.read_line(&mut line) => {
if result.unwrap() == 0 {
break;
}
tx.send((line.clone(), addr)).unwrap();
line.clear();
}
result = rx.recv() => {
let (msg, other_addr) = result.unwrap();
if addr != other_addr {
writer.write_all(msg.as_bytes()).await.unwrap();
}
}
}
}
});
}
}YouTube 链接:(19) Creating a Chat Server with async Rust and Tokio - YouTube
From 日报小组 长琴
社区学习交流平台订阅: