首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >【Rust 日报】2021-06-06 TheAlgorithms Rust 实现

【Rust 日报】2021-06-06 TheAlgorithms Rust 实现

作者头像
MikeLoveRust
发布2021-06-16 10:44:41
发布2021-06-16 10:44:41
7300
举报

TheAlgorithms: Rust

大名鼎鼎的 The Algorithms 的 Rust 版本,使用 Rust 实现所有算法。

GitHub 地址:TheAlgorithms/Rust: All Algorithms implemented in Rust

Rustpad:开源协作文本编辑器

  • 高效且最小的协作代码编辑器、自托管、无需数据库
  • 使用 warp web服务框架和 operational-transform 库
  • 使用 wasm-bindgen 将文本操作逻辑编译为在浏览器运行的 WebAssembly 代码
  • 客户端通过 WebSocket 与存储内存数据结构的中央 server 通信

GitHub 地址:ekzhang/rustpad: Efficient and minimal collaborative code editor, self-hosted, no database required

textwrap:一个用于包装和缩进文本的库

代码语言:javascript
复制
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.

linya:轻量并发进度条

GitHub 地址:fosskers/linya: Simple concurrent progress bars.

youchoose:一个简单易用的 Rust 命令行菜单

GitHub 地址:nathom/youchoose: A lightweight terminal menu for Rust

使用 Tokio 创建简单聊天服务器

仅使用 tokio 实现的简单聊天服务器:

代码语言:javascript
复制
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 日报小组 长琴

社区学习交流平台订阅:

  • Rustcc 论坛:支持 rss
  • 微信公众号:Rust 语言中文社区
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2021-06-06,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 Rust语言学习交流 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • TheAlgorithms: Rust
  • Rustpad:开源协作文本编辑器
  • textwrap:一个用于包装和缩进文本的库
  • linya:轻量并发进度条
  • youchoose:一个简单易用的 Rust 命令行菜单
  • 使用 Tokio 创建简单聊天服务器
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档