【Rust日报】2020-06-08

≡放荡痞女 提交于 2021-02-14 16:52:27

mlua v0.4 发布并支持Lua 5.4

mlua v0.4 released with Lua 5.4 support
https://github.com/khvzak/mlua
mlua  v0.4 发布并支持Lua 5.4。
v0.4 changelog

MiniCouchDB: implementing a subset of CouchDB in Rust

MiniCouchDB: implementing a subset of CouchDB in Rust
https://www.garrensmith.com/blogs/mini-couch-hack-week   https://github.com/garrensmith/couch_hack_week
mini-redis 启发,搞了一个 mini-CouchDB in Rust .

Benchrs: Apache Benchmark(ab) clone in rust

Benchrs: Apache Benchmark(ab) clone in rust  https://crates.io/crates/benchrs
Apache Benchmark style http bench tool written in async rust.

   
   
   
Benchrs 0.1.7
Arkaitz Jimenez <arkaitzj@gmail.com>
Does http benchmarks

USAGE:
benchrs [FLAGS] [OPTIONS] <url>

FLAGS:
-h, --help Prints help information
-k Enables keep alive
-V, --version Prints version information
-v Increases verbosity

OPTIONS:
-c <concurrency> Sets the concurrency level
-H <header>... Sets a custom header
-m <method> Request method: default GET
-p <postfile> File attach as request body
-n <request number> Sets the number of requests

ARGS:
<url> The url to hit

Rust/WinRT快速入门

Getting started with Rust/WinRT
https://kennykerr.ca/2020/06/05/getting-started-with-rust-winrt/
加拿大小伙子Kenny Kerr写的Rust/WinRT编程快速入门。
Rust/WinRT编程快速入门已经非常简单,这得益于程序员喜欢的Rust语言编程工具链提供了大量的便利。如果你想不需要额外的帮助直接入门,下面是一些有用的链接
  • GitHub:  https://github.com/microsoft/winrt-rs
  • Docs.rs:  https://docs.rs/winrt/
  • Crates.io:  https://crates.io/crates/winrt
下面会给一些个人的心得和小技巧:
安装先决条件和工具:
  • Visual Studio 2019  – be sure to install the C++ tools as this is required by the Rust compiler (only the linker is required).
  • Visual Studio Code  – this is the default IDE used for Rust.
  • Python  – be sure to install the x64 version as this is required for debugging support.
  • Git  – Rust has deep support for Git.
  • Rust  – this installs  rustup  which is a tool for installing Rust toolchains and common Rust related tooling.
打开VS Code然后键入 Ctrl+Shift+X 打开扩展页安装下面的extensions:
  • rust-analyzer – there are others, but this is the only Rust extension that I’ve tried that actually works reliably most of the time.
  • CodeLLDB – you can also use the Microsoft C++ extension for debugging, but this one does a better job of integrating with the IDE.
  • C/C++ – the Microsoft C++ extension doesn’t integrate as well with the IDE, but provides superior debugging information, so you may want to have that on hand for an emergency.
提示下载并安装Rust language server,确认安装,然后重新启动IDE。然后我们开始用新的cargo包创建例子:

   
   
   
C:\>cargo new sample
Created binary (application) `sample` package

C:\>cd sample
C:\sample>code .
新创建的项目目录下修改Cargo.toml配置文件,并添加WinRT的依赖库包:

   
   
   
[dependencies]
winrt = "0.7.0"
确认所有的库是最新的,然后开始编译项目:

   
   
   
C:\sample>cargo build
Updating crates.io index
Compiling proc-macro2 v1.0.18
Compiling unicode-xid v0.2.0
...
Compiling winrt_gen_macros v0.7.0
Compiling winrt_gen v0.7.0
Compiling winrt_macros v0.7.0
Compiling winrt v0.7.0
Compiling sample v0.1.0 (C:\sample)
Finished dev [unoptimized + debuginfo] target(s) in 19.65s

C:\sample>cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.06s
Running `target\debug\sample.exe`
Hello, world!
在项目文件夹里找到写hello world的源文件main.rs,我们用winrt::import macro来生成Rust bindings for WinRT的APIs:

   
   
   
winrt::import!(
dependencies
os
types
windows::data::xml::dom::*
);
其实你在main.rs里面任何位置放置上面的代码都可以,这个导入的宏分成两个部分:一类是你的项目中需要标识WinRT组件,另一类是特别需要相应的类型子集。这里用了 os 表示需要运行的操作系统,也可以指定特定版本的Windows SDK。然后指定了官方文档中的一些类型 windows::data::xml::dom  下面还有用了 XmlDocument ,具体的细节可以参考 官方文档 :

   
   
   
fn main() -> winrt::Result<()> {
use windows::data::xml::dom::*;

let doc = XmlDocument::new()?;
doc.load_xml("<html>hello world</html>")?;

let root = doc.document_element()?;
assert!(root.node_name()? == "html");
assert!(root.inner_text()? == "hello world");

Ok(())
}
编译运行的结果:

   
   
   
C:\sample>cargo run
Compiling sample v0.1.0 (C:\sample)
Finished dev [unoptimized + debuginfo] target(s) in 8.71s
Running `target\debug\sample.exe`
这样,import宏导进来的库就可以开始调用指定的 Windows API 了。

rust语言写斗兽棋游戏

Animal Fight Chess Game written in rust.
https://github.com/netcan/AnimalChess
Animal Fight Chess Game(斗兽棋) written in rust. Rust语言写斗兽棋游戏
游戏规则和玩法:
  • http://ancientchess.com/page/play-doushouqi.htm
  • https://en.wikipedia.org/wiki/Jungle_(board_game)
编译和运行:

   
   
   
git clone https://github.com/netcan/AnimalChess.git
cd AnimalChess
cargo run --release
From 日报小组 BobQ

本文分享自微信公众号 - Rust语言中文社区(rust-china)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!