Write Powerful Rust Macros (撰寫強大的 Rust 巨集)

Van Overmeire, Sam

  • 出版商: Manning
  • 出版日期: 2024-07-16
  • 售價: $2,160
  • 貴賓價: 9.5$2,052
  • 語言: 英文
  • 頁數: 320
  • 裝訂: Quality Paper - also called trade paper
  • ISBN: 1633437493
  • ISBN-13: 9781633437494
  • 相關分類: Rust 語言
  • 立即出貨

相關主題

商品描述

An example-driven, step-by-step guide to success with Rust macros.

In Write Powerful Rust Macros you'll learn how to use these amazing metaprogramming tools to push Rust to its full potential. This hands-on guide takes you from the absolute basics to advanced macro techniques, exploring Rust macros through interesting and engaging examples.

Inside Write Powerful Rust Macros you'll discover:

  • Writing declarative macros
  • Procedural macros
  • Reading and debugging macro code
  • Improving the type system with newtypes and zero-sized types
  • How common Rust libraries use macros

Write Powerful Rust Macros teaches you how to write, test, debug, and publish macros for Rust. It's perfect for Rust practitioners who want to master this powerful development technique. Build your knowledge chapter-by-chapter. You'll start with declarative macros before diving into the real power: procedural macros that can generate code, augment data structures, and even create domain-specific languages.

Purchase of the print book includes a free eBook in PDF and ePub formats from Manning Publications.

About the technology

Macros are one of Rust's most important and powerful tools. Although notoriously challenging, this metaprogramming technique has a big payoff. Using macros to generate new Rust code at compile-time can save you hours of tedious coding with negligible runtime performance impact. This book shows you exactly how to master this Rust superpower.

About the book

Write Powerful Rust Macros opens up the world of macros to intermediate Rust programmers. You'll start with declarative macros to get the basics under your belt. Then, you'll advance to procedural macros as you automatically generate a builder, learn to create your own domain-specific languages, and more. As you go, you'll develop practical skills like testing macros, integrating macros with crates, and even sharing your macros with other developers.

What's inside

  • How Rust libraries use macros
  • Reading and debugging macro code
  • newtypes and the type state pattern

About the reader

For intermediate Rust programmers.

About the author

Sam Van Overmeire is an experienced Rust developer and the author of multiple books, scientific articles and blog posts.

The technical editor on this book was Andrew Lilley Brinker.

Table of contents

1 Going meta
2 Declarative macros
3 A "Hello, World" procedural macro
4 Making fields public with attribute macros
5 Hiding information and creating mini-DSLs with function-like macros
6 Testing a builder macro
7 From panic to result: Error handling
8 Builder with attributes
9 Writing an infrastructure DSL
10 Macros and the outside world

商品描述(中文翻譯)

一本以實例為基礎的、逐步引導讀者成功使用 Rust 宏的指南。

在《寫出強大的 Rust 宏》中,您將學習如何使用這些令人驚嘆的元編程工具,將 Rust 的潛力發揮到極致。這本實踐指南將帶領您從基礎知識到高級宏技巧,通過有趣且引人入勝的實例探索 Rust 宏。

在《寫出強大的 Rust 宏》中,您將會發現:

- 編寫聲明性宏
- 過程宏
- 讀取和調試宏代碼
- 通過新類型和零大小類型改進類型系統
- 常見的 Rust 函式庫如何使用宏

《寫出強大的 Rust 宏》教您如何為 Rust 編寫、測試、調試和發布宏。這本書非常適合想要掌握這種強大開發技術的 Rust 從業者。您將逐章建立知識,從聲明性宏開始,然後深入探索真正的力量:可以生成代碼、增強數據結構甚至創建特定領域語言的過程宏。

購買印刷版書籍還包括 Manning Publications 提供的 PDF 和 ePub 格式的免費電子書。

關於技術:

宏是 Rust 最重要且最強大的工具之一。儘管宏技術聞名於難度,但它帶來了巨大的回報。在編譯時使用宏生成新的 Rust 代碼可以節省您大量繁瑣的編碼時間,並且對運行時性能影響微乎其微。本書將向您展示如何精通這種 Rust 超能力。

關於本書:

《寫出強大的 Rust 宏》將宏的世界打開給中級 Rust 程序員。您將從聲明性宏入門,掌握基礎知識。然後,您將進一步學習過程宏,自動生成構建器,學會創建自己的特定領域語言等等。在此過程中,您將發展實用技能,如測試宏、將宏與庫集成,甚至與其他開發人員共享宏。

內容概要:

- Rust 函式庫如何使用宏
- 讀取和調試宏代碼
- 新類型和類型狀態模式

關於讀者:

適合中級 Rust 程序員閱讀。

關於作者:

Sam Van Overmeire 是一位經驗豐富的 Rust 開發人員,也是多本書籍、科學文章和博客文章的作者。

本書的技術編輯是 Andrew Lilley Brinker。

目錄:

1. 走向元編程
2. 聲明性宏
3. "Hello, World" 過程宏
4. 使用屬性宏使字段公開
5. 使用函數式宏隱藏信息並創建迷你 DSL
6. 測試構建器宏
7. 從 panic 到 result:錯誤處理
8. 帶有屬性的構建器
9. 編寫基礎設施 DSL
10. 宏與外部世界

作者簡介

Sam Van Overmeire is a software developer with a background in history and archaeology. He is the author of multiple books, scientific articles and blog posts.

作者簡介(中文翻譯)

Sam Van Overmeire 是一位具有歷史和考古學背景的軟體開發者。他是多本書籍、科學文章和部落格文章的作者。