What you will learn in Write Powerful Rust Macros
Chapter by chapter
Chapter 5: Hiding information and creating mini-DSLs with function-like macros
What you learn in chapter 5 →Concepts explained in this book
- TokenStreamA token stream is a sequence of Rust tokens used as input or output during macro expansion and source-code generation.
- declarative macromacro_rules! is Rust's declaration syntax for defining declarative macros from matcher and transcriber rules.
- macroA Rust macro is a compile-time language construct that generates or transforms Rust source code through expansion.
- derive macroA Rust derive attribute requests compiler or procedural generation of trait implementations for a type.
- attribute macroAn attribute macro is a Rust procedural macro that defines a custom attribute and replaces the annotated item with generated output.
- result typeResult is the Rust standard-library enum representing either successful output or an error value.
- parsingParsing is the process of analyzing an input sequence according to a grammar and constructing its syntactic structure.
- domain-specific languageA domain-specific language is a language designed to express concepts and operations within a particular application domain.
- genericsA generic function is a function parameterized by types or other compile-time parameters.
- quotequote is a Rust library and macro for generating source-token streams from interpolated syntax.
- procedural macroA procedural macro is a Rust macro implemented as code that receives a token stream and programmatically produces another token stream.
- macro matcherA macro matcher is the pattern portion of a declarative macro rule that determines which invocation tokens the rule accepts.
- builder patternThe builder pattern constructs a complex value through an intermediate builder with configurable operations before finalization.
- function-like macroA function-like macro is a Rust procedural macro invoked with the ! operator that accepts arbitrary token input and replaces that input with generated output.
- abstract syntax treeAn abstract syntax tree is a hierarchical representation of a program's syntactic structure and relevant semantic elements.
- AWS LambdaAWS Lambda is a serverless computing platform that runs code in response to events without requiring users to manage servers.
- macro transcriberA macro transcriber is the output-template portion of a declarative macro definition that specifies generated syntax for a matched invocation.
- DeriveInputDeriveInput is a syn syntax structure representing the input item received by a derive macro, including a struct or enum.
- type stateThe type state pattern encodes an object's permitted states in its type so invalid state transitions or configurations are rejected at compile time.
- bucketA bucket is a cloud-infrastructure storage resource that holds collections of objects or similar data.
- token treeA Rust token tree is a syntactic token or delimited sequence of tokens that can be captured as a broadly permissive macro fragment.
- black-box testingBlack-box testing evaluates software through externally observable behavior and public interfaces without relying on implementation details.
- compositionFunction composition combines functions so that the output of one becomes the input of another.
- proc-macro crate settingA proc-macro library is a Rust crate whose exported procedural macro items are compiled for use during another crate's compilation.
- parse_macro_inputparse_macro_input is a syn-provided procedural macro that parses a procedural macro's input token stream into a specified Rust syntax type.
- cargo featureA Cargo feature is a named compile-time configuration option that conditionally enables additive crate functionality or dependencies.
- marker traitA marker trait is a trait with no methods or associated properties that classifies implementing types.
- Amazon S3Amazon S3 is an object storage service whose data is organized into named storage containers called buckets.
- AWS SDK for RustAWS SDK for Rust is a Rust library providing programmatic clients for interacting with AWS services.
- punctuatedPunctuated is a syn sequence structure that stores syntax elements together with their punctuation separators.
- compilation testA compile test is a software test whose expected outcome is successful compilation of generated or written code.
- parse2parse2 is a syn function that parses a proc-macro2 token stream into a specified Rust syntax type and checks that the input has been fully consumed.
- newtype idiomA newtype is a distinct wrapper type around an existing value that gives the value stronger type-level meaning and can enforce construction invariants.
- white-box testingWhite-box testing evaluates software with knowledge of and access to its internal implementation, including private code paths.
- expressionA Rust expression is a syntactic construct that evaluates to a value.
- panicA panic is Rust's unrecoverable failure mechanism that stops ordinary execution and may unwind the stack to clean up resources.
- compile timeCompile time is the phase in which source code is analyzed and transformed into an executable or library artifact.
- syn::Errorsyn::Error is syn's error type for reporting parsing and syntax-processing failures with source spans and diagnostic messages.
- macro recursionMacro recursion is the expansion behavior in which a macro invocation expands to another invocation of the same macro.
- orphan ruleAn orphan rule restricts trait implementations so that at least the trait or the implemented type is local to the defining crate.
- compile-time errorA compile error is a compiler diagnostic indicating that source code violates language or compilation rules and cannot be successfully compiled.
- blanket implementationA blanket implementation is a trait implementation written for every type satisfying specified bounds.
- fragment specifierA fragment specifier is the annotation in a declarative macro matcher that selects the syntactic category accepted by a metavariable.
- macro parameterA macro variable is a named binding in a declarative macro that refers to syntax captured by a matcher.
- macro repetitionA macro repetition operator specifies whether a repeated macro pattern occurs zero or more, one or more, or zero or one times.
- metavariableA metavariable is a declarative-macro binding whose fragment specifier determines the syntactic category of captured input.
- ToTokensToTokens is a quote trait whose implementations convert Rust syntax-related values into token streams.
- impure functionAn impure function is a function whose behavior or result can depend on or produce effects beyond its input parameters.
- pure functionA pure function is a function with no observable side effects whose result depends only on its input parameters.
- custom keywordA custom keyword is a syntax token declared through syn's custom_keyword macro that implements parsing and lookahead support for a DSL-specific keyword.
- metaprogrammingMetaprogramming is the practice of writing code that treats other code as data so it can manipulate or generate code or add capabilities.
- cargo checkcargo check is a Cargo command that compiles a Rust project for error checking without producing a final executable.
- LitIntLitInt is syn's syntax structure representing a Rust integer literal together with its source span.
- DefaultDefault is the standard Rust trait for constructing a default value of a type.
- MetaListMetaList is a syn syntax structure representing list-form Rust metadata such as an attribute path followed by nested arguments.
- proc_macro_errorproc_macro_error is a Rust library that provides procedural-macro facilities for reporting compile-time errors with reduced boilerplate.
- variadic argumentsVariadic arguments are function-call arguments whose number is determined at the call site rather than fixed by the declaration.
- parse_nested_metaparse_nested_meta is a syn parsing operation that iterates over nested metadata inside an attribute and delegates each entry to a callback.
- infrastructure as codeInfrastructure as code is the practice of defining and managing computing infrastructure through executable code or declarative machine-readable configuration.
- matcher-transcriber pairA matcher-transcriber pair is a declarative macro rule consisting of an input matcher and its corresponding output transcriber.
- DataStructDataStruct is a syn syntax structure representing the parsed components and data of a Rust struct declaration.
- syn dataData is a syn enum representing whether a parsed input contains a struct, enum, or union.
- syn fieldField is a syn syntax structure representing a Rust struct or enum field and its properties.
- macro expansionMacro expansion is the process of replacing a macro invocation with the source code generated or transformed by that macro.
- monomorphizationMonomorphization is the compilation transformation that creates concrete specialized copies of a generic function for the types with which it is instantiated.
- proc_macro_deriveproc_macro_derive is the Rust attribute that marks a procedural macro function as a derive macro implementation and assigns its invocation name.
- tokenizationLexing is the process of converting raw source text into a sequence of lexical tokens.
- cargo-expandcargo expand is a Cargo subcommand that displays the Rust source code produced by macro expansion.
- inert attributeAn inert attribute is an attribute that remains available during processing rather than removing itself during macro expansion.
- call_sitecall_site is a Span-associated function that creates a span resolved at the location where a procedural macro is invoked.
- identifier fragment specifierAn identifier fragment specifier matches an identifier token as an input fragment in a Rust declarative macro.
- type fragment specifierA type fragment specifier is a declarative-macro matcher specifier that matches Rust type syntax.
- cargo init commandcargo init is a Cargo command that creates a new Rust package with generated project files.
- rename attributeA rename attribute is the book-specific helper attribute that specifies an alternate property name for generated builder code.
- integration testIntegration testing evaluates the behavior and interactions of multiple software components, often across external system boundaries.
- active attributeAn active attribute is an attribute that is removed during attribute processing after its macro expands.
- trybuildtrybuild is a Rust testing tool for compiling test cases and checking their expected compiler errors or successful compilation.
- macro hygieneMacro hygiene is the property that prevents identifiers introduced or referenced by a macro expansion from unintentionally colliding with identifiers in surrounding code.
- end-to-end testingAn end-to-end test evaluates the workings of an entire system using most or all of its real dependencies.
- algebraic data typeAn algebraic data type is a composite type formed from product and sum type constructors to represent a defined set of values.
- EitherEither is a sum-type pattern representing one of two alternatives, conventionally a successful result or a failure.
- enumAn enum is a Rust sum type with a fixed set of named variants that may carry associated data and methods.
- product typeA product type is a composite type whose possible values are combinations of values from all its component fields.
- additive featureAn additive feature is a crate feature that only adds functionality and does not disable functionality already available.
- conditional compilationConditional compilation is the selection of source items for compilation based on compile-time configuration conditions.
- returntypeReturnType is a syn syntax structure representing a Rust function's return-type syntax, including either no explicit type or an arrow followed by a type.
- AWSAWS is Amazon Web Services, a cloud computing platform providing infrastructure and managed application services.
- AWS CloudFormationAWS CloudFormation is an AWS infrastructure-as-code service that provisions and updates resources from declarative templates.
- no-panicno-panic is a Rust procedural macro library that statically verifies that annotated functions cannot panic.
- absolute pathA full path is a Rust path that identifies an item through its complete namespace qualification.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.
