0
点赞
收藏
分享

微信扫一扫

【Rust日报】2022-03-28 我的第一个 Clippy Lint

我的第一个 Clippy Lint

作者自己动手写了一个clippy的 lint,其过程比他想象中的要简单和容易测试的多. Clippy团队在提供示例、快速代码审查和大量易于使用的共享utils代码方面做了大量工作。

原文链接: https://jamesmcm.github.io/blog/2022/03/26/my-first-clippy-lint/#en

ProjClean: 查找和清理 build 和 cache 目录

ProjClean 会为你找到 node_modules(node)、target(rust)、build(java)等目录及其存储空间,所以你可以很容易地检查或清理。

【Rust日报】2022-03-28 我的第一个 Clippy Lint_代码审查

github 地址: https://github.com/sigoden/projclean

axum-auth: HTTP auth extractor

提供 Axum 下的 HTTP auth extractor. 支持 Bearer 和 Basic Auth.

Bearer Authentication:

use axum_auth::AuthBearer;

/// Handler for a typical axum route, takes a `token` and returns it
async fn handler(AuthBearer(token): AuthBearer) -> String {
format!("Found a bearer token: {}", token)
}

Basic Authentication:

use axum_auth::AuthBasic;

/// Takes basic auth details and shows a message
async fn handler(AuthBasic((id, password)): AuthBasic) -> String {
if let Some(password) = password {
format!("User '{}' with password '{}'", id, password)
} else {
format!("User '{}' without password", id)
}
}

github 连接: https://github.com/Owez/axum-auth

expectrl

Expectrl 是一个rust模块,用于生成子应用程序,控制它们,并在进程的输出中响应预期的模式

使用该库你可以:

  • Spawn process
  • Control process
  • Interact with process's IO(input/output).

use expectrl::{spawn, Regex, Eof, WaitStatus, Error};

fn main() -> Result<(), Error> {
let mut p = spawn("ftp speedtest.tele2.net")?;
p.expect(Regex("Name \\(.*\\):"))?;
p.send_line("anonymous")?;
p.expect("Password")?;
p.send_line("test")?;
p.expect("ftp>")?;
p.send_line("cd upload")?;
p.expect("successfully changed.\r\nftp>")?;
p.send_line("pwd")?;
p.expect(Regex("[0-9]+ \"/upload\""))?;
p.send_line("exit")?;
p.expect(Eof)?;
assert_eq!(p.wait()?, WaitStatus::Exited(p.pid(), 0));
}

github地址: https://github.com/zhiburt/expectrl

--


社区学习交流平台订阅:

  • Rustcc论坛: 支持rss
  • 微信公众号:Rust语言中文社区


举报

相关推荐

0 条评论