I can't keep up with idiomatic Rust

栏目: IT技术 · 发布时间: 5年前

Recently withoutboats posted a series of blog posts about some syntax sugar he would like added to Rust.

The gist of it is, as far as I can tell, there should be some way to not have to write Ok(...) for the happy path in functions which return Result . He specifically is advocating for a throws keyword that would go a bit beyond just this basic change, but the problem he’s mainly trying to fix is having to type Ok(...) so often.

I haven’t really been involved with the Rust community that much, especially since I stopped working on Way Cooler. This isn’t from lack of using Rust, I use Rust in my day job after all, but rather from disinterest in getting involved in what seems to be mostly bikeshedding. The .await war was the final straw to make me stop watching the Rust community beyond what comes in the release notes.

So in many ways I’m coming into this argument as an outsider – I have not read any thing beyond the two linked blog posts and am missing most of the discussion that has gone on. I’m not going to weigh in on throws vs some annotation vs Fehler because even though I have an opinion I detest bikeshedding.

However, as a long time user of Rust (4 years, wow how time flies!) the constantly changing standard of what constitutes “idiomatic Rust” is starting to wear me down. try!() -> ? , the addition of impl trait , and the dyn keyword are all features that have changed what it means to write idiomatic Rust. When these features come out I need to now change my code in order to keep it idiomatic.

That’s not to say I hate these features. I remember being very happy when ? came about and dyn is certainly clearer than what we had before. However having to make these superficial changes again and again causes churn in all my codebases. Because Rust releases every 6 weeks that means every 6 weeks I might need to make superficial changes to my codebase (not to mention potentially have to do a major point release – using impl is an API breaking change).

So to bring my complaints back around to the issue at hand: if Ok wrapping came in the next Rust release this would be another change that requires me to update my code in order to be idiomatic. This isn’t sustainable for me – I appreciate Rust team’s commitment to backwards compatibility but the constant disregard for forwards-compatibility makes me feel like I’m on a treadmill trying, and failing, to keep up.


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

多任务下的数据结构与算法

多任务下的数据结构与算法

周伟明 / 华中科技 / 2006-4 / 58.00元

本书和传统同类书籍的区别是除了介绍基本的数据结构容器如栈、队列、链表、树、二叉树、红黑树、AVL树和图之外,引进了多任务;还介绍了将任意数据结构容器变成支持多任务的方法;另外,还增加了复合数据结构和动态数据结构等新内容的介绍。在复合数据结构中不仅介绍了哈希链表、哈希红黑树、哈希AVL树等容器,还介绍了复合数据结构的通用设计方法;在动态数据结构中主要介绍了动态环形队列、动态等尺寸内存管理算法。在内存......一起来看看 《多任务下的数据结构与算法》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具