Function-like procedural macros
Function-like procedural macros are procedural macros that are invoked using the macro invocation operator (!). These macros are defined by a public function with the proc_macro attribute and a signature of (TokenStream) -> TokenStream. The input TokenStream is what is inside the delimiters of the macro invocation and the output TokenStream replaces the entire macro invocation. For example, the following macro definition ignores its input and outputs a function answer into its scope.
Derive macro helper attributes
Derive macros define new inputs for the derive attribute. These macros can create new items given the token stream of a struct, enum, or union. They can also define derive macro helper attributes. Custom derive macros are defined by a public function with the proc_macro_derive attribute and a signature of (TokenStream) -> TokenStream. The input TokenStream is the token stream of the item that has the derive attribute on it. The output TokenStream must be a set of items that are then appended to the module or block that the item from the input TokenStream is in.
What Is Ownership
Rust’s central feature is ownership. Although the feature is straightforward to explain, it has deep implications for the rest of the language. All programs have to manage the way they use a computer’s memory while running. Some languages have garbage collection that constantly looks for no longer used memory as…