Crate nu_derive_value

Source
Expand description

Macro implementations of #[derive(FromValue, IntoValue)].

As this crate is a proc_macro crate, it is only allowed to export procedural macros. Therefore, it only exports IntoValue and FromValue.

To get documentation for other functions and types used in this crate, run cargo doc -p nu-derive-value --document-private-items.

This crate uses a lot of proc_macro2::TokenStream as TokenStream2 to allow testing the behavior of the macros directly, including the output token stream or if the macro errors as expected. The tests for functionality can be found in nu_protocol::value::test_derive.

This documentation is often less reference-heavy than typical Rust documentation. This is because this crate is a dependency for nu_protocol, and linking to it would create a cyclic dependency. Also all examples in the documentation aren’t tested as this crate cannot be compiled as a normal library very easily. This might change in the future if cargo allows building a proc-macro crate differently for cfg(doctest) as they are already doing for cfg(test).

The generated code from the derive macros tries to be as hygienic as possible. This ensures that the macro can be called anywhere without requiring specific imports. This results in obtuse code, which isn’t recommended for manual, handwritten Rust but ensures that no other code may influence this generated code or vice versa.

Derive Macros§

  • Derive macro generating an impl of the trait FromValue.
  • Derive macro generating an impl of the trait IntoValue.