Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

高级功能

Advanced Features

到目前为止,你已经学习了 Rust 编程语言中最常用的部分。在我们在第 21 章进行最后一个项目之前,我们将了解该语言的一些你可能偶尔会遇到但可能不会每天使用的方面。当遇到任何未知内容时,你可以将本章作为参考。这里介绍的功能在非常特定的情况下非常有用。虽然你可能不会经常用到它们,但我们希望确保你掌握了 Rust 提供的所有功能。

By now, you’ve learned the most commonly used parts of the Rust programming language. Before we do one more project, in Chapter 21, we’ll look at a few aspects of the language you might run into every once in a while but may not use every day. You can use this chapter as a reference for when you encounter any unknowns. The features covered here are useful in very specific situations. Although you might not reach for them often, we want to make sure you have a grasp of all the features Rust has to offer.

在本章中,我们将介绍:

In this chapter, we’ll cover:

  • 不安全 Rust:如何选择退出 Rust 的某些保证,并负责手动维护这些保证

  • Unsafe Rust: How to opt out of some of Rust’s guarantees and take responsibility for manually upholding those guarantees

  • 高级 trait:关联类型、默认类型参数、完全限定语法、父 trait 以及与 trait 相关的 Newtype 模式

  • Advanced traits: Associated types, default type parameters, fully qualified syntax, supertraits, and the newtype pattern in relation to traits

  • 高级类型:关于 Newtype 模式、类型别名、Never 类型和动态大小类型的更多内容

  • Advanced types: More about the newtype pattern, type aliases, the never type, and dynamically sized types

  • 高级函数和闭包:函数指针和返回闭包

  • Advanced functions and closures: Function pointers and returning closures

  • 宏:在编译时定义更多代码的代码定义方式

  • Macros: Ways to define code that defines more code at compile time

这是一系列琳琅满目的 Rust 功能,每个人都能从中有所收获!让我们开始吧!

It’s a panoply of Rust features with something for everyone! Let’s dive in!