Rust is a programming language focused on safety, particularly safe concurrency, supporting functional and imperative-procedural paradigms. Rust is syntactically similar to C++, but it provides memory safety without using garbage collection.
Rust是一种专注于安全性的编程语言,特别是安全并发,支持函数式和强制过程式范式。Rust在语法上类似于C++,但它提供了内存安全,而不使用垃圾收集。
It achieves this through a system of ownership with a set of rules that the compiler checks at compile time. Though it does not prevent all possible bugs, it guarantees memory safety by ensuring that certain kinds of bugs, like buffer overflows or access to uninitialized memory, are caught during compilation. If you didn’t read my last reading please have a look through that.
它通过一个所有权系统和一组编译器在编译时检查的规则来实现这一点。虽然它不能防止所有可能的错误,但它通过确保在编译期间捕获某些类型的错误(如缓冲区溢出或对未初始化内存的访问)来保证内存安全。
Rust has low latency Rust具有低延迟
Latency for a round-trip network request and response depends both on network latency and service latency. Network latency is affected by many factors, such as transmission medium, propagation distance, router efficiency, and network bandwidth.
往返网络请求和响应的延迟取决于网络延迟和服务延迟。网络延迟受许多因素影响,例如传输介质、传播距离、路由器效率和网络带宽。
Service latency depends on many factors, such as I/O delays in processing the request, whether there is a garbage collector that introduces non-deterministic delays, Hypervisor pauses, the amount of context switching (e.g., in multithreading), serialization and deserialization costs, etc.
服务延迟取决于许多因素,例如处理请求时的I/O延迟、是否存在引入非确定性延迟的垃圾收集器、Hypervisor暂停、上下文切换量(例如,在多线程中)、串行化和非串行化成本等。
From a purely programming language perspective, Rust provides low latency due to its low-level hardware control as a systems programming language.
从纯粹的编程语言的角度来看,Rust提供了低延迟,因为它是一种系统编程语言,具有低级别的硬件控制。
Rust does not have a garbage collector or runtime, and it has native support for non-blocking I/O, a good ecosystem of high-performance async (non-blocking) I/O libraries and runtimes, and zero-cost abstractions as a fundamental design principle of the language.
Rust没有垃圾收集器或运行时,它对非阻塞I/O有原生支持,一个良好的高性能非阻塞I/O库和运行时生态系统,以及作为语言基本设计原则的零成本抽象。
Zero-Cost Abstractions 零成本抽象
Rust’s “zero-cost abstractions” mean that its abstractions cost as little as possible in terms of runtime performance. In practice, using high-level abstractions in Rust does not result in slower code than if you wrote your program in a lower-level language. This principle ensures that developers do not have to compromise on expressiveness or safety for the sake of performance.
Rust的“零成本抽象”意味着它的抽象在运行时性能方面的成本尽可能少。实际上,在Rust中使用高级抽象并不会导致代码比用低级语言编写程序更慢。这一原则确保开发人员不必为了性能而在表达性或安全性上做出妥协。Additionally, by default, Rust variables live on the stack, which is faster to manage.
此外,默认情况下,Rust变量位于堆栈上,这更容易管理。
Rust enables fearless concurrency
Rust支持无畏的并发
Rust is a concurrency-friendly language that enables developers to use the power of multi-core processors. Rust provides two types of concurrency: classic multithreading and asynchronous I/O:
Rust是一种并发友好的语言,使开发人员能够使用多核处理器的功能。Rust提供了两种类型的并发:经典多线程和异步I/O:
- Multithreading — Rust’s traditional multithreading support provides for both shared-memory and message-passing concurrency. Type-level guarantees are provided for the sharing of values. Threads can borrow values, assume ownership, and transition the scope of a value to a new thread. Rust also provides data-race safety, which prevents thread-blocking, improving performance.
多线程-Rust的传统多线程支持同时提供共享内存和消息传递并发。类型级别的保证是为了共享值而提供的。线程可以借用值,取得所有权,并将值的范围转换到新线程。Rust还提供了数据竞争安全,防止线程阻塞,提高性能。- In order to improve memory efficiency and avoid the copying of data shared across threads,
为了提高内存效率并避免复制跨线程共享的数据,- Rust provides reference counting as a mechanism to track the use of a variable by other processes or threads. The value is dropped when the count reaches zero, which provides for safe memory management. Additionally, mutexes are available in Rust for data synchronization across threads. References to immutable data need not use mutex.
Rust提供引用计数作为一种机制来跟踪其他进程或线程对变量的使用。当计数达到零时,该值将被删除,这提供了安全的内存管理。此外,互斥锁在Rust中可用于跨线程的数据同步。对不可变数据的引用不需要使用互斥量。- Async I/O — Async event-loop–based non-blocking I/O concurrency primitives are built into the Rust language with zero-cost futures and async-await. Non-blocking I/O ensures that code does not hang while waiting for data to be processed.
Async I/O -基于Async事件循环的非阻塞I/O并发原语内置于Rust语言中,具有零成本future和alphanc-await。非阻塞I/O确保代码在等待数据处理时不会挂起。
Further, Rust’s rules of immutability provide for high levels of data concurrency.
此外,Rust的不变性规则提供了高级别的数据并发性。
Rust is a productive language
Rust是一种生产性语言
Even though Rust is first a systems-oriented programming language, it also adds the quality-of-life features of higher-level and functional programming languages. These are a few of the higher-level abstractions in Rust that make for a productive and delightful developer experience:
尽管Rust首先是一种面向系统的编程语言,但它也增加了高级和函数式编程语言的生活质量特性。这些是Rust中的一些更高级别的抽象,可以为开发人员提供高效和愉快的体验:
- Closures with anonymous functions
使用匿名函数的闭包- Iterators 迭代器
- Generics and macros 泛型和宏
- Enums such as Option and Result
枚举,如Option和Result- Polymorphism through traits
通过性状的多态性- Dynamic dispatch through Trait objects
通过Trait对象进行动态分派
Rust not only allows developers to build efficient, safe, and performant software, it also optimizes for developer productivity with its expressiveness.
Rust不仅允许开发人员构建高效,安全和高性能的软件,还通过其表现力优化了开发人员的生产力。