Simple Console Input API for Standard Library
StrawPoll.com:
我们正试图将一个简单的控制台输入API推送到标准库中,以使编写简单的命令行输入变得更容易,我们需要社区决定实现的高级程度。因为这是一个相当有争议的话题(双方的数量非常均匀),所以这次投票就是为了解决这个问题。
注意:下面的例子不是最终的,它只是一个用来阐述这个概念的例子。
简单输入的例子:
let age: i32 = std::inputln!()?.parse().expect("Invalid age!");
高级输入的例子:
let person = scan!("{} {}", String, u8).expect("Invalid input!");
或者
let name: String;
let age: u8;
scan!("{} {}", name, age).expect("Invalid input!");
「投票」:
如果想参与投票,请访问原文投票。
Is rust good for mathematical computing?
科学计算相关的任务:
对编程语言的要求:
Rust语言本身对lambda(在Rust中称为闭包)、通用组合和函数式编程有很好的支持,但像柯里化(curry)这样的东西看起来并不漂亮。
目前Rust语言实现的跟科学计算相关的crate列表,可以在此查看:Scientific Computing
Testing multiple implementations of a trait in Rust
文中介绍了几种测试trait实现逻辑的实用方法:
另外也可以使用test-case 这个crate
来进行测试:
pub trait Calculator {
fn new() -> Self;
fn add(&self, a: u32, b: u32) -> u32;
}
pub struct Foo {}
impl Calculator for Foo {
fn new() -> Self {
Self {}
}
fn add(&self, a: u32, b: u32) -> u32 {
a + b
}
}
pub struct Bar {}
impl Calculator for Bar {
fn new() -> Self {
Self {}
}
fn add(&self, a: u32, b: u32) -> u32 {
if b == 0 {
a
} else {
self.add(a, b - 1) + 1
}
}
}
#[cfg(test)]
mod tests {
use super::{Bar, Calculator, Foo};
use test_case::test_case;
#[test_case(Foo::new())]
#[test_case(Bar::new())]
fn trait_tester(c: impl Calculator) {
assert_eq!(c.add(2, 3), 5);
assert_eq!(c.add(10, 43), 53);
}
}
How variables are saved in Python and Rust. Side by Side 4: str/string
在Python3中,和str相关的结构体有三个:
PyASCIIObject
:纯ascii字符串;PyCompactUnicodeObject
:Unicode字符串;PyUnicodeObject
:兼容历史API的Unicode字符串。在Rust中,和string相关的类型有:
&str
:字符串切片;String
:动态扩容的字符串;Get stats and the energy consumption of your docker containers
Docker activity是一种用于监视Docker容器统计信息并输出其能耗的工具。
当前它还处于早期阶段,对于demoing来说,它很快就会变得更好。。。
项目地址:
Docker Activity
From 日报小组 odd-cat
社区学习交流平台订阅:
Rust.cc 论坛: 支持 rss
微信公众号:Rust 语言中文社区