nushell/crates
Piepmatz b79a2255d2
Add derive macros for FromValue and IntoValue to ease the use of Values in Rust code (#13031)
# Description
After discussing with @sholderbach the cumbersome usage of
`nu_protocol::Value` in Rust, I created a derive macro to simplify it.
I’ve added a new crate called `nu-derive-value`, which includes two
macros, `IntoValue` and `FromValue`. These are re-exported in
`nu-protocol` and should be encouraged to be used via that re-export.

The macros ensure that all types can easily convert from and into
`Value`. For example, as a plugin author, you can define your plugin
configuration using a Rust struct and easily convert it using
`FromValue`. This makes plugin configuration less of a hassle.

I introduced the `IntoValue` trait for a standardized approach to
converting values into `Value` (and a fallible variant `TryIntoValue`).
This trait could potentially replace existing `into_value` methods.
Along with this, I've implemented `FromValue` for several standard types
and refined other implementations to use blanket implementations where
applicable.

I made these design choices with input from @devyn.

There are more improvements possible, but this is a solid start and the
PR is already quite substantial.

# User-Facing Changes

For `nu-protocol` users, these changes simplify the handling of
`Value`s. There are no changes for end-users of nushell itself.

# Tests + Formatting
Documenting the macros itself is not really possible, as they cannot
really reference any other types since they are the root of the
dependency graph. The standard library has the same problem
([std::Debug](https://doc.rust-lang.org/stable/std/fmt/derive.Debug.html)).
However I documented the `FromValue` and `IntoValue` traits completely.

For testing, I made of use `proc-macro2` in the derive macro code. This
would allow testing the generated source code. Instead I just tested
that the derived functionality is correct. This is done in
`nu_protocol::value::test_derive`, as a consumer of `nu-derive-value`
needs to do the testing of the macro usage. I think that these tests
should provide a stable baseline so that users can be sure that the impl
works.

# After Submitting
With these macros available, we can probably use them in some examples
for plugins to showcase the use of them.
2024-06-17 16:05:11 -07:00
..
nu_plugin_custom_values Add derive macros for FromValue and IntoValue to ease the use of Values in Rust code (#13031) 2024-06-17 16:05:11 -07:00
nu_plugin_example bump version to 0.94.3 (#13055) 2024-06-05 06:52:40 +08:00
nu_plugin_formats bump version to 0.94.3 (#13055) 2024-06-05 06:52:40 +08:00
nu_plugin_gstat bump version to 0.94.3 (#13055) 2024-06-05 06:52:40 +08:00
nu_plugin_inc bump version to 0.94.3 (#13055) 2024-06-05 06:52:40 +08:00
nu_plugin_nu_example bump version to 0.94.3 (#13055) 2024-06-05 06:52:40 +08:00
nu_plugin_polars Allow the addition of an index column to be optional (#13097) 2024-06-10 10:45:25 +08:00
nu_plugin_python bump version to 0.94.3 (#13055) 2024-06-05 06:52:40 +08:00
nu_plugin_query Make query xml return nodes in document order (#13047) 2024-06-05 09:47:36 +08:00
nu_plugin_stress_internals bump version to 0.94.3 (#13055) 2024-06-05 06:52:40 +08:00
nu-cli add $nu.data-dir for completions and $nu.cache-dir for other uses (#13122) 2024-06-11 15:10:31 -04:00
nu-cmd-base Add derive macros for FromValue and IntoValue to ease the use of Values in Rust code (#13031) 2024-06-17 16:05:11 -07:00
nu-cmd-extra Make which-support feature non-optional (#13125) 2024-06-12 20:04:12 -05:00
nu-cmd-lang Added search terms to if (#13145) 2024-06-13 19:55:17 -05:00
nu-cmd-plugin bump version to 0.94.3 (#13055) 2024-06-05 06:52:40 +08:00
nu-color-config bump version to 0.94.3 (#13055) 2024-06-05 06:52:40 +08:00
nu-command Add derive macros for FromValue and IntoValue to ease the use of Values in Rust code (#13031) 2024-06-17 16:05:11 -07:00
nu-derive-value Add derive macros for FromValue and IntoValue to ease the use of Values in Rust code (#13031) 2024-06-17 16:05:11 -07:00
nu-engine Span ID Refactor (Step 2): Use SpanId of expressions in some places (#13102) 2024-06-09 12:15:53 +03:00
nu-explore Improve performance of explore - 1 (#13116) 2024-06-12 18:35:04 -07:00
nu-glob bump version to 0.94.3 (#13055) 2024-06-05 06:52:40 +08:00
nu-json bump version to 0.94.3 (#13055) 2024-06-05 06:52:40 +08:00
nu-lsp bump version to 0.94.3 (#13055) 2024-06-05 06:52:40 +08:00
nu-parser Span ID Refactor - Step 1 (#12960) 2024-06-05 09:57:14 +08:00
nu-path add $nu.data-dir for completions and $nu.cache-dir for other uses (#13122) 2024-06-11 15:10:31 -04:00
nu-plugin bump version to 0.94.3 (#13055) 2024-06-05 06:52:40 +08:00
nu-plugin-core bump version to 0.94.3 (#13055) 2024-06-05 06:52:40 +08:00
nu-plugin-engine bump version to 0.94.3 (#13055) 2024-06-05 06:52:40 +08:00
nu-plugin-protocol bump version to 0.94.3 (#13055) 2024-06-05 06:52:40 +08:00
nu-plugin-test-support bump version to 0.94.3 (#13055) 2024-06-05 06:52:40 +08:00
nu-pretty-hex bump version to 0.94.3 (#13055) 2024-06-05 06:52:40 +08:00
nu-protocol Add derive macros for FromValue and IntoValue to ease the use of Values in Rust code (#13031) 2024-06-17 16:05:11 -07:00
nu-std Return an empty list when no std help --find results are found (#13160) 2024-06-15 12:27:55 -05:00
nu-system bump version to 0.94.3 (#13055) 2024-06-05 06:52:40 +08:00
nu-table Improve performance of explore - 1 (#13116) 2024-06-12 18:35:04 -07:00
nu-term-grid bump version to 0.94.3 (#13055) 2024-06-05 06:52:40 +08:00
nu-test-support bump version to 0.94.3 (#13055) 2024-06-05 06:52:40 +08:00
nu-utils add $nu.data-dir for completions and $nu.cache-dir for other uses (#13122) 2024-06-11 15:10:31 -04:00
nuon Span ID Refactor - Step 1 (#12960) 2024-06-05 09:57:14 +08:00
README.md Remove old nushell/merge engine-q 2022-02-07 14:54:06 -05:00

Nushell core libraries and plugins

These sub-crates form both the foundation for Nu and a set of plugins which extend Nu with additional functionality.

Foundational libraries are split into two kinds of crates:

  • Core crates - those crates that work together to build the Nushell language engine
  • Support crates - a set of crates that support the engine with additional features like JSON support, ANSI support, and more.

Plugins are likewise also split into two types:

  • Core plugins - plugins that provide part of the default experience of Nu, including access to the system properties, processes, and web-connectivity features.
  • Extra plugins - these plugins run a wide range of different capabilities like working with different file types, charting, viewing binary data, and more.