rustprograming吧 关注:1,083贴子:41
  • 0回复贴,共1

欢迎来到Rust中文吧!

只看楼主收藏回复

Rust介绍¶
Rust 是一门系统级别的编程语言。
Rust 由 Graydon Hoare 开发并在被 Mozilla 实验室收购后发扬光大。
Rust 是一门系统级编程语言,被设计为保证内存和线程安全,防止段错误产生。作为系统级编程语言,它的基本理念是“零开销抽象”。理论上来说,它的速度与 C/C++ 同级。Rust 可以被归为通用的、多范式、编译型的编程语言,类似 C/C++。与这两门编程语言不同的是,Rust 是线程安全的!Rust 编程语言的目标是,创建一个安全和并发的软件系统。它强调安全性、并发和内存控制。尽管 Rust 借用了 C/C++ 的语法,却杜绝了空指针和悬挂指针,而这二者是 C/C++ 中系统崩溃、内存泄露和不安全代码的根源。
那我为什么要学习rust,这个问题我觉得官方网站就有答案。
对比其他语言¶
这里我们比较的是相关语言在处理一些函数的速度,数据来源debian的benchmarksgame,如下图:
rust对比c
为什么选择 Rust ?¶
正如 Rust 语言自己说的那样,Rust 语言有三大愿景:
高安全
高性能
高并发
Rust 语言旨在以简单的方式开发高度可靠和快速的软件。
Rust 语言支持用现代语言特性来写一些系统级别乃至机器级别的程序。
高性能¶
高性能是所有语言的最高追求,Rust 也不例外。
为了追求极致的性能,Rust 抛弃了 C/C++ 之外的语言都有的 垃圾回收器( Garbage Collector )。
也就是消除了垃圾回收机制带来的性能损耗。
编译时内存安全¶
Rust 虽然也有指针的概念,但这个概念被大大的弱化,因此它没有 C/C++ 那种悬空指针,缓冲区溢出和内存泄漏等等问题。
天生多线程安全运行程序¶
Rust 是为多线程高并发而设计的系统级别语言,Rust 的 拥有者(ownership) 概念和 内存安全 规则使得它天生支持高并发,而且是支持没有数据竞争的高并发。
Rust 语言支持 Web Assembly (WASM) 语言¶
Rust 的目标是成为高并发且高安全的系统级语言,但这并不代表它就不能开发 Web 应用,Rust 支持通过把代码编译成 Web Assembly (WASM) 语言从而能够在浏览器端以实现快速,可靠的运行。
Web Assembly (WASM) 语言是被设计用来在浏览器端/嵌入式设别上运行的,用于执行 CPU 计算密集型的语言,也就是说 Web Assembly (WASM) 语言 的目标是和 Javascript 一样能够在浏览器里运行,但因为是编译型,所以更高效。
--转自站点 网页链接
《The Rust Programming Language》
It wasn’t always so clear, but the Rust programming language is fundamentally about empowerment: no matter what kind of code you are writing now, Rust empowers you to reach farther, to program with confidence in a wider variety of domains than you did before.
Take, for example, “systems-level” work that deals with low-level details of memory management, data representation, and concurrency. Traditionally, this realm of programming is seen as arcane, accessible only to a select few who have devoted the necessary years learning to avoid its infamous pitfalls. And even those who practice it do so with caution, lest their code be open to exploits, crashes, or corruption.
Rust breaks down these barriers by eliminating the old pitfalls and providing a friendly, polished set of tools to help you along the way. Programmers who need to “dip down” into lower-level control can do so with Rust, without taking on the customary risk of crashes or security holes, and without having to learn the fine points of a fickle toolchain. Better yet, the language is designed to guide you naturally towards reliable code that is efficient in terms of speed and memory usage.
Programmers who are already working with low-level code can use Rust to raise their ambitions. For example, introducing parallelism in Rust is a relatively low-risk operation: the compiler will catch the classical mistakes for you. And you can tackle more aggressive optimizations in your code with the confidence that you won’t accidentally introduce crashes or vulnerabilities.
But Rust isn’t limited to low-level systems programming. It’s expressive and ergonomic enough to make CLI apps, web servers, and many other kinds of code quite pleasant to write — you’ll find simple examples of both later in the book. Working with Rust allows you to build skills that transfer from one domain to another; you can learn Rust by writing a web app, then apply those same skills to target your Raspberry Pi.
----------------------------------------------
虽然不是那么明显,但 Rust 程序设计语言的本质在于 赋能(empowerment):无论你现在编写的是何种代码,Rust 能让你在更为广泛的编程领域走得更远,写出自信。
比如,“系统层面”(“systems-level”)的工作,涉及内存管理、数据表示和并发等底层细节。从传统角度来看,这是一个神秘的编程领域,只为浸润多年的极少数人所触及,也只有他们能避开那些臭名昭著的陷阱。即使谨慎的实践者,亦唯恐代码出现漏洞、崩溃或损坏。
Rust 破除了这些障碍,其消除了旧的陷阱并提供了伴你一路同行的友好、精良的工具。想要 “深入” 底层控制的程序员可以使用 Rust,无需冒着常见的崩溃或安全漏洞的风险,也无需学习时常改变的工具链的最新知识。其语言本身更是被设计为自然而然的引导你编写出在运行速度和内存使用上都十分高效的可靠代码。
已经在从事编写底层代码的程序员可以使用 Rust 来提升抱负。例如,在 Rust 中引入并行是相对低风险的操作:编译器会为你捕获经典的错误。同时你可以自信的采取更为积极的优化,而不会意外引入崩溃或漏洞。
但 Rust 并不局限于底层系统编程。其表现力和工效足以令人愉悦的编写出 CLI 应用、web server 和很多其他类型的代码 —— 在本书中你会看到两个简单示例。使用 Rust 能将你在一个领域中学习的技能延伸到另一个领域;你可以学习 Rust 来编写 web 应用,接着将同样的技能应用到你的 Raspberry Pi(树莓派)上。


IP属地:四川来自Android客户端1楼2022-01-20 14:17回复