赞
踩
Rust和c++是两种流行的系统编程语言。多年来,c++的焦点一直放在性能上。我们越来越多地听到来自客户和安全研究人员的呼吁,认为c++语言应该有更强的安全保证。Visual Studio 2019 version 16.7 在c++的核心检查中包含了四个新规则,以将Rust的一些安全特性合并到c++中。
文章链接,https://devblogs.microsoft.com/cppblog/new-safety-rules-in-c-core-check/
就在昨天,这个Rust PR(我正在做的)每晚都被合并到Rust中,这对编译器错误有着广泛的影响。
在这篇文章中,我描述了这种变化以及从中可以期待什么。
在错误中完整路径的问题:如下所示的简单程序将导致类型错误。
- fn main() {
- let a = vec![vec![String::from("a")]];
- let b = vec![String::from("b")];
- a == b;
- }
-
类型错误可以描述为:cannot compare between values of the types Vec<Vec<String>> and Vec<String>
。在PR改变之前,这几乎是错误信息的第一行,其余的错误信息提供了更多关于特征的细节:
- error[E0277]: can't compare `std::vec::Vec<std::string::String>` with `std::string::String`
- --> example.rs:5:7
- |
- 5 | a == b;
- | ^^ no implementation for `std::vec::Vec<std::string::String> == std::string::String`
- |
- = help: the trait `std::cmp::PartialEq<std::string::String>` is not implemented for `std::vec::Vec<std::string::String>`
- = note: required because of the requirements on the impl of `std::cmp::PartialEq<std::vec::Vec<std::string::String>>` for `std::vec::Vec<std::vec::Vec<std::string::String>>`
值得注意的是,在上述错误中,造成认知负担的最大因素是类型和特征的完整合格路径(例如std::vec:: vec)。对很多人来说,它的可读性有很大的不同。
文章链接,https://blog.aloni.org/posts/path-trimming-in-rust-nightly/
在我的twitch频道最近的Rust问答环节中,有人问了一个看起来很简单的问题:为什么像SmartString或SmolStr这样的小字符串类型和string一样大小,而像SmallVec这样的小vec类型却比vec大?
我知道我刚刚用了形容词simple,但事实是:为了理解这个问题,我们需要一些背景知识。
文章链接,https://fasterthanli.me/articles/peeking-inside-a-rust-enum
From 日报小组 TOM
社区学习交流平台订阅:
Rustcc论坛: 支持rss
微信公众号:Rust语言中文社区
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。