02 2022 档案
摘要:环境 Time 2022-01-11 Rust 1.57.0 Tokio 1.15.0 概念 参考:https://docs.rs/tokio/latest/tokio/runtime/struct.Builder.html 默认情况下,Tokio 启动的工作线程数和 CPU 核数相等,也可以自定义
阅读全文
摘要:环境 Time 2022-01-11 Rust 1.57.0 Tokio 1.15.0 概念 参考:https://docs.rs/tokio/latest/tokio/runtime/struct.Builder.html 除了使用 new 直接创建的方式,还可以使用 Builder 来构建运行时
阅读全文
摘要:环境 Time 2022-01-11 Rust 1.57.0 Tokio 1.15.0 概念 参考:https://docs.rs/tokio/latest/tokio/runtime/struct.Builder.html 在线程空闲和运行时,可以定义一个回调。 示例 main.rs use st
阅读全文
摘要:环境 Time 2022-01-11 Rust 1.57.0 Tokio 1.15.0 概念 参考:https://docs.rs/tokio/latest/tokio/runtime/struct.Builder.html 通过 thread_name 和 thread_name_fn 可以对线程
阅读全文
摘要:环境 Time 2022-01-11 Rust 1.57.0 Tokio 1.15.0 概念 参考:https://docs.rs/tokio/latest/tokio/runtime/struct.Builder.html 对于阻塞任务,Tokio 会新启动一个线程来运行,可以设置启动的最大线程数
阅读全文
摘要:环境 Time 2022-01-11 Rust 1.57.0 Tokio 1.15.0 概念 参考:https://docs.rs/tokio/latest/tokio/runtime/struct.Builder.html 对于阻塞任务,Tokio 会新启动一个线程来运行,这个也是在一个线程池中,
阅读全文
摘要:环境 Time 2022-01-11 Rust 1.57.0 Tokio 1.15.0 概念 参考:https://docs.rs/tokio/latest/tokio/runtime/struct.Builder.html 在线程启动和结束时,可以定义一个回调。 示例 main.rs use st
阅读全文
摘要:环境 Time 2022-01-11 Rust 1.57.0 Tokio 1.15.0 概念 参考:https://docs.rs/tokio/latest/tokio/runtime/struct.Builder.html 除了可以使用线程池运行时,还可以直接在当前线程运行任务,使用单线程。 示例
阅读全文
摘要:环境 Time 2022-01-11 Rust 1.57.0 Tokio 1.15.0 概念 参考:https://docs.rs/tokio/latest/tokio/runtime/struct.Builder.html Tokio 除了是一个异步运行时外,还提供了其它方面的功能,可以进行开启。
阅读全文
摘要:环境 Time 2022-01-10 Rust 1.57.0 Tokio 1.15.0 概念 参考:https://docs.rs/tokio/latest/tokio/runtime/struct.Runtime.html handle 方法返回一个可以执行任务的句柄。 示例 main.rs us
阅读全文
摘要:环境 Time 2022-01-10 Rust 1.57.0 Tokio 1.15.0 概念 参考:https://docs.rs/tokio/latest/tokio/runtime/struct.Runtime.html enter 方法可以进入异步运行时的上下文。 示例 main.rs use
阅读全文
摘要:环境 Time 2022-01-10 Rust 1.57.0 Tokio 1.15.0 概念 参考:https://docs.rs/tokio/latest/tokio/runtime/struct.Runtime.html spawn_blocking 方法可以接收一个闭包,可以是一个阻塞任务。
阅读全文
摘要:环境 Time 2022-01-10 Rust 1.57.0 Tokio 1.15.0 概念 参考:https://docs.rs/tokio/latest/tokio/runtime/struct.Runtime.html block_on 方法可以接收一个异步任务,在当前线程中运行并阻塞直到完成
阅读全文
摘要:环境 Time 2022-01-10 Rust 1.57.0 Tokio 1.15.0 概念 参考:https://docs.rs/tokio/latest/tokio/runtime/struct.Runtime.html shutdown_background 方法可以立即关闭运行时,不会产生阻
阅读全文
摘要:环境 Time 2022-01-10 Rust 1.57.0 Tokio 1.15.0 概念 参考:https://docs.rs/tokio/latest/tokio/runtime/struct.Runtime.html shutdown_timeout 方法关闭运行时会阻塞,等待任务完成。参数
阅读全文
摘要:环境 Time 2022-01-10 Rust 1.57.0 Tokio 1.15.0 概念 参考:https://docs.rs/tokio/latest/tokio/runtime/struct.Runtime.html spawn 方法可以接收一个异步任务,在工作线程中运行,并不产生阻塞。 示
阅读全文
摘要:环境 Time 2022-01-10 Rust 1.57.0 Tokio 1.15.0 概念 参考:https://docs.rs/tokio/latest/tokio/runtime/struct.Runtime.html Tokio 是 Rust 的一个异步运行时库,提供了标准库的异步版本,Ru
阅读全文
摘要:环境 Time 2022-01-08 Rust 1.57.0 mio 0.8 概念 参考:https://github.com/tokio-rs/mio/blob/master/examples/tcp_server.rs 将客户端发送的消息转为大写后返回。 UDP 服务器基本功能实现完成,只能做练
阅读全文
摘要:环境 Time 2022-01-08 Rust 1.57.0 mio 0.8 概念 参考:https://github.com/tokio-rs/mio/blob/master/examples/tcp_server.rs 监听客户端关闭连接。 示例 关闭标记 loop { match client
阅读全文
摘要:环境 Time 2022-01-08 Rust 1.57.0 mio 0.8 概念 参考:https://github.com/tokio-rs/mio/blob/master/examples/tcp_server.rs 处理读取时数据超长问题。 TCP 服务器基本功能实现完成,只能做练习使用,不
阅读全文
摘要:环境 Time 2022-01-08 Rust 1.57.0 mio 0.8 概念 参考:https://github.com/tokio-rs/mio/blob/master/examples/tcp_server.rs 实现小写转大写的应答消息。 示例 应答消息 fn handle_client
阅读全文
摘要:环境 Time 2022-01-08 Rust 1.57.0 mio 0.8 概念 参考:https://github.com/tokio-rs/mio/blob/master/examples/tcp_server.rs main 函数越来越长,将长函数分割成功能较少的小函数。 示例 accept
阅读全文
摘要:环境 Time 2022-01-08 Rust 1.57.0 mio 0.8 概念 参考:https://github.com/tokio-rs/mio/blob/master/examples/tcp_server.rs 接受客户端发送的数据。 示例 读取数据 if event.is_readab
阅读全文
摘要:环境 Time 2022-01-08 Rust 1.57.0 mio 0.8 概念 参考:https://github.com/tokio-rs/mio/blob/master/examples/tcp_server.rs 实现多个客户端同时连接的功能。 示例 存储不同的连接 let mut cli
阅读全文
摘要:环境 Time 2022-01-07 Rust 1.57.0 mio 0.8 概念 参考:https://github.com/tokio-rs/mio/blob/master/examples/tcp_server.rs 连接建立后,得到一个 socket,使用 epoll 监听可读可写事件。 示
阅读全文
摘要:环境 Time 2022-01-07 Rust 1.57.0 mio 0.8 概念 参考:https://github.com/tokio-rs/mio/blob/master/examples/tcp_server.rs 在可写事件发生后,向客户端写入一条消息。 示例 保留连接 let mut s
阅读全文
摘要:环境 Time 2022-01-07 Rust 1.57.0 mio 0.8 概念 参考:https://github.com/tokio-rs/mio/blob/master/examples/tcp_server.rs mio 是跨平台的非阻塞 IO 库,在其它平台实现类似 linux 下 ep
阅读全文
摘要:环境 Time 2022-01-07 Rust 1.57.0 mio 0.8 概念 参考:https://github.com/tokio-rs/mio/blob/master/examples/tcp_server.rs epoll 的触发方式有两种,一种是水平触发(Level Trigger,L
阅读全文
摘要:环境 Time 2021-12-07 Rust 1.57.0 serde 1.0.130 serde_json 1.0.72 概念 参考:https://serde.rs/container-attrs.html 示例 #[serde(rename = "xxxx")] 针对序列化和反序列化同名 #
阅读全文
摘要:环境 Time 2021-12-07 Rust 1.57.0 serde 1.0.130 serde_json 1.0.72 概念 参考:https://serde.rs/convert-error.html 示例 main.rs use serde::{Deserialize, Serialize
阅读全文
摘要:环境 Time 2021-12-06 Rust 1.57.0 serde 1.0.130 serde_json 1.0.72 概念 参考:https://serde.rs/attr-skip-serializing.html 示例 main.rs use serde::Serialize; use
阅读全文
摘要:环境 Time 2021-12-06 Rust 1.57.0 serde 1.0.130 serde_json 1.0.72 概念 参考:https://serde.rs/deserialize-map.html 示例 main.rs use std::fmt; use serde::{de::Vi
阅读全文
摘要:环境 Time 2021-12-04 Rust 1.57.0 serde 1.0.130 serde_json 1.0.72 概念 参考:https://serde.rs/attr-flatten.html 示例 组合公共属性 use serde::{Deserialize, Serialize};
阅读全文
摘要:环境 Time 2021-12-02 VSCode 1.61.2 Rust 1.56.1 概念 参考:https://docs.serde.rs/serde_json/index.html#serde-json 示例 main.rs use serde::Serialize; #[derive(Se
阅读全文
摘要:环境 Time 2021-12-07 Rust 1.57.0 serde 1.0.130 serde_json 1.0.72 概念 参考:https://serde.rs/feature-flags.html 示例 serde 有几个特性标签,可以在 Cargo 引入的时候,选择性打开。类似如下的方
阅读全文
摘要:环境 Time 2021-12-07 Rust 1.57.0 serde 1.0.130 serde_json 1.0.72 概念 参考:https://serde.rs/transcode.html 示例 main.rs use std::io; fn main() { // A JSON inp
阅读全文
摘要:环境 Time 2021-12-06 Rust 1.57.0 serde 1.0.130 serde_json 1.0.72 概念 参考:https://serde.rs/enum-number.html 示例 main.rs use serde_repr::*; #[derive(Serializ
阅读全文
摘要:环境 Time 2021-12-04 Rust 1.57.0 serde 1.0.130 serde_json 1.0.72 概念 参考:https://serde.rs/enum-representations.html 示例 外部标签 use serde::{Deserialize, Seria
阅读全文
摘要:环境 Time 2021-12-02 VSCode 1.61.2 Rust 1.56.1 Serde 1.0.72 概念 参考:https://docs.serde.rs/serde_json/index.html#serde-json 示例 可以在 JSON 中写变量。 main.rs use s
阅读全文
摘要:环境 Time 2021-12-07 Rust 1.57.0 serde 1.0.130 serde_json 1.0.72 概念 参考:https://serde.rs/container-attrs.html 示例 main.rs use serde::{Deserialize, Seriali
阅读全文
摘要:环境 Time 2021-12-06 Rust 1.57.0 serde 1.0.130 serde_json 1.0.72 概念 参考:https://serde.rs/attr-rename.html 示例 main.rs use serde::Serialize; #[derive(Seria
阅读全文
摘要:环境 Time 2021-12-07 Rust 1.57.0 serde 1.0.130 serde_json 1.0.72 概念 参考:https://serde.rs/string-or-struct.html 示例 main.rs use std::collections::BTreeMap
阅读全文
摘要:环境 Time 2021-12-04 Rust 1.57.0 serde 1.0.130 serde_json 1.0.72 概念 参考:https://serde.rs/attr-default.html 示例 调用 default 函数 use serde::{Deserialize, Seri
阅读全文
摘要:环境 Time 2021-12-07 Rust 1.57.0 serde 1.0.130 serde_json 1.0.72 概念 参考:https://serde.rs/field-attrs.html 示例 main.rs use serde::{Deserialize, Serialize};
阅读全文
摘要:环境 Time 2021-12-06 Rust 1.57.0 serde 1.0.130 serde_json 1.0.72 概念 参考:https://stackoverflow.com/questions/37870428/convert-two-types-into-a-single-type
阅读全文
摘要:环境 Time 2021-12-07 Rust 1.57.0 serde 1.0.130 serde_json 1.0.72 概念 参考:https://serde.rs/container-attrs.html 示例 lowercase 全小写 UPPERCASE 全大写 PascalCase 大
阅读全文