nushell/crates/nu-protocol/src/value
Piepmatz 9b7f899410
Allow missing fields in derived FromValue::from_value calls (#13206)
# Description
In #13031 I added the derive macros for `FromValue` and `IntoValue`. In
that implementation, in particular for structs with named fields, it was
not possible to omit fields while loading them from a value, when the
field is an `Option`. This PR adds extra handling for this behavior, so
if a field is an `Option` and that field is missing in the `Value`, then
the field becomes `None`. This behavior is also tested in
`nu_protocol::value::test_derive::missing_options`.

# User-Facing Changes
When using structs for options or similar, users can now just emit
fields in the record and the derive `from_value` method will be able to
understand this, if the struct has an `Option` type for that field.

# Tests + Formatting
- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# After Submitting
A showcase for this feature would be great, I tried to use the current
derive macro in a plugin of mine for a config but without this addition,
they are annoying to use. So, when this is done, I would add an example
for such plugin configs that may be loaded via `FromValue`.
2024-06-22 13:31:09 -07:00
..
custom_value.rs Make drop notification timing for plugin custom values more consistent (#12341) 2024-04-04 09:13:25 +02:00
duration.rs Restructure nu-protocol in more meaningful units (#11917) 2024-03-10 18:45:45 +01:00
filesize.rs Remove some macros (#12742) 2024-05-03 10:35:37 +02:00
from.rs Spanned Value step 1: span all value cases (#10042) 2023-08-25 08:48:05 +12:00
from_value.rs Fix compilation for nu_protocol::value::from_value on 32-bit targets (#13169) 2024-06-18 07:16:08 -05:00
glob.rs ls, rm, cp, open, touch, mkdir: Don't expand tilde if input path is quoted string or a variable. (#12232) 2024-03-25 10:08:38 +08:00
into_value.rs 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
mod.rs 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
range.rs Range refactor (#12405) 2024-04-06 09:04:56 -05:00
record.rs Impl FusedIterator for record iterators (#12542) 2024-04-17 00:34:16 +02:00
test_derive.rs Allow missing fields in derived FromValue::from_value calls (#13206) 2024-06-22 13:31:09 -07:00