mirror of
https://github.com/nushell/nushell.git
synced 2025-05-08 03:54:27 +02:00
# Description While working on something else, I noticed that `Value::follow_cell_path` receives `self`. While it would be ideal for the signature to be `(&'a self, cell_path) -> &'a Value`, that's not possible because: 1. Selecting a row from a list and field from a record can be done with a reference but selecting a column from a table requires creating a new list. 2. `Value::Custom` returns new `Value`s when indexed. So the signature becomes `(&'a self, cell_path) -> Cow<'a, Value>`. Another complication that arises is, once a new `Value` is created, and it is further indexed, the `current` variable 1. can't be `&'a Value`, as the lifetime requirement means it can't refer to local variables 2. _shouldn't_ be `Cow<'a, Value>`, as once it becomes an owned value, it can't be borrowed ever again, as `current` is derived from its previous value in further iterations. So once it's owned, it can't be indexed by reference, leading to more clones We need `current` to have _two_ possible lifetimes 1. `'out`: references derived from `&self` 2. `'local`: references derived from an owned value stored in a local variable ```rust enum MultiLife<'out, 'local, T> where 'out: 'local, T: ?Sized, { Out(&'out T), Local(&'local T), } ``` With `current: MultiLife<'out, '_, Value>`, we can traverse values with minimal clones, and we can transform it to `Cow<'out, Value>` easily (`MultiLife::Out -> Cow::Borrowed, MultiLife::Local -> Cow::Owned`) to return it # User-Facing Changes # Tests + Formatting # After Submitting --------- Co-authored-by: Bahex <17417311+Bahex@users.noreply.github.com> |
||
---|---|---|
.. | ||
nu_plugin_custom_values | ||
nu_plugin_example | ||
nu_plugin_formats | ||
nu_plugin_gstat | ||
nu_plugin_inc | ||
nu_plugin_javascript | ||
nu_plugin_nu_example | ||
nu_plugin_polars | ||
nu_plugin_python | ||
nu_plugin_query | ||
nu_plugin_stress_internals | ||
nu-cli | ||
nu-cmd-base | ||
nu-cmd-extra | ||
nu-cmd-lang | ||
nu-cmd-plugin | ||
nu-color-config | ||
nu-command | ||
nu-derive-value | ||
nu-engine | ||
nu-explore | ||
nu-glob | ||
nu-json | ||
nu-lsp | ||
nu-parser | ||
nu-path | ||
nu-plugin | ||
nu-plugin-core | ||
nu-plugin-engine | ||
nu-plugin-protocol | ||
nu-plugin-test-support | ||
nu-pretty-hex | ||
nu-protocol | ||
nu-std | ||
nu-system | ||
nu-table | ||
nu-term-grid | ||
nu-test-support | ||
nu-utils | ||
nuon | ||
README.md |
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.