nushell/crates
Ian Manske 6fd854ed9f
Replace ExternalStream with new ByteStream type (#12774)
# Description
This PR introduces a `ByteStream` type which is a `Read`-able stream of
bytes. Internally, it has an enum over three different byte stream
sources:
```rust
pub enum ByteStreamSource {
    Read(Box<dyn Read + Send + 'static>),
    File(File),
    Child(ChildProcess),
}
```

This is in comparison to the current `RawStream` type, which is an
`Iterator<Item = Vec<u8>>` and has to allocate for each read chunk.

Currently, `PipelineData::ExternalStream` serves a weird dual role where
it is either external command output or a wrapper around `RawStream`.
`ByteStream` makes this distinction more clear (via `ByteStreamSource`)
and replaces `PipelineData::ExternalStream` in this PR:
```rust
pub enum PipelineData {
    Empty,
    Value(Value, Option<PipelineMetadata>),
    ListStream(ListStream, Option<PipelineMetadata>),
    ByteStream(ByteStream, Option<PipelineMetadata>),
}
```

The PR is relatively large, but a decent amount of it is just repetitive
changes.

This PR fixes #7017, fixes #10763, and fixes #12369.

This PR also improves performance when piping external commands. Nushell
should, in most cases, have competitive pipeline throughput compared to,
e.g., bash.
| Command | Before (MB/s) | After (MB/s) | Bash (MB/s) |
| -------------------------------------------------- | -------------:|
------------:| -----------:|
| `throughput \| rg 'x'` | 3059 | 3744 | 3739 |
| `throughput \| nu --testbin relay o> /dev/null` | 3508 | 8087 | 8136 |

# User-Facing Changes
- This is a breaking change for the plugin communication protocol,
because the `ExternalStreamInfo` was replaced with `ByteStreamInfo`.
Plugins now only have to deal with a single input stream, as opposed to
the previous three streams: stdout, stderr, and exit code.
- The output of `describe` has been changed for external/byte streams.
- Temporary breaking change: `bytes starts-with` no longer works with
byte streams. This is to keep the PR smaller, and `bytes ends-with`
already does not work on byte streams.
- If a process core dumped, then instead of having a `Value::Error` in
the `exit_code` column of the output returned from `complete`, it now is
a `Value::Int` with the negation of the signal number.

# After Submitting
- Update docs and book as necessary
- Release notes (e.g., plugin protocol changes)
- Adapt/convert commands to work with byte streams (high priority is
`str length`, `bytes starts-with`, and maybe `bytes ends-with`).
- Refactor the `tee` code, Devyn has already done some work on this.

---------

Co-authored-by: Devyn Cairns <devyn.cairns@gmail.com>
2024-05-16 07:11:18 -07:00
..
nu-cli Replace ExternalStream with new ByteStream type (#12774) 2024-05-16 07:11:18 -07:00
nu-cmd-base Implement PWD recovery (#12779) 2024-05-10 11:06:33 -05:00
nu-cmd-dataframe Replace ExternalStream with new ByteStream type (#12774) 2024-05-16 07:11:18 -07:00
nu-cmd-extra Replace ExternalStream with new ByteStream type (#12774) 2024-05-16 07:11:18 -07:00
nu-cmd-lang Replace ExternalStream with new ByteStream type (#12774) 2024-05-16 07:11:18 -07:00
nu-cmd-plugin Make the message when running a plugin exe directly clearer (#12806) 2024-05-07 20:12:32 -07:00
nu-color-config Replace ExternalStream with new ByteStream type (#12774) 2024-05-16 07:11:18 -07:00
nu-command Replace ExternalStream with new ByteStream type (#12774) 2024-05-16 07:11:18 -07:00
nu-engine Replace ExternalStream with new ByteStream type (#12774) 2024-05-16 07:11:18 -07:00
nu-explore Replace ExternalStream with new ByteStream type (#12774) 2024-05-16 07:11:18 -07:00
nu-glob Bump version to 0.93.1 (#12710) 2024-05-01 17:19:20 -05:00
nu-json Minimize future false positive typos (#12751) 2024-05-04 15:00:44 +00:00
nu-lsp Refactor the CLI code a bit (#12782) 2024-05-10 07:29:27 +08:00
nu-parser allow passing float value to custom command (#12879) 2024-05-16 10:50:29 +02:00
nu-path Fix trailing slash in PWD set by cd (#12760) 2024-05-04 12:38:37 +03:00
nu-plugin Replace ExternalStream with new ByteStream type (#12774) 2024-05-16 07:11:18 -07:00
nu-plugin-core Replace ExternalStream with new ByteStream type (#12774) 2024-05-16 07:11:18 -07:00
nu-plugin-engine Replace ExternalStream with new ByteStream type (#12774) 2024-05-16 07:11:18 -07:00
nu-plugin-protocol Replace ExternalStream with new ByteStream type (#12774) 2024-05-16 07:11:18 -07:00
nu-plugin-test-support Replace ExternalStream with new ByteStream type (#12774) 2024-05-16 07:11:18 -07:00
nu-pretty-hex Bump version to 0.93.1 (#12710) 2024-05-01 17:19:20 -05:00
nu-protocol Replace ExternalStream with new ByteStream type (#12774) 2024-05-16 07:11:18 -07:00
nu-std Update PR template (#12838) 2024-05-13 08:45:44 -05:00
nu-system Replace ExternalStream with new ByteStream type (#12774) 2024-05-16 07:11:18 -07:00
nu-table Avoid taking unnecessary ownership of intermediates (#12740) 2024-05-04 00:53:15 +00:00
nu-term-grid Bump version to 0.93.1 (#12710) 2024-05-01 17:19:20 -05:00
nu-test-support Avoid taking unnecessary ownership of intermediates (#12740) 2024-05-04 00:53:15 +00:00
nu-utils overhaul shell_integration to enable individual control over ansi escape sequences (#12629) 2024-05-02 09:56:50 -04:00
nu_plugin_custom_values Bump version to 0.93.1 (#12710) 2024-05-01 17:19:20 -05:00
nu_plugin_example Replace ExternalStream with new ByteStream type (#12774) 2024-05-16 07:11:18 -07:00
nu_plugin_formats Bump version to 0.93.1 (#12710) 2024-05-01 17:19:20 -05:00
nu_plugin_gstat Bump version to 0.93.1 (#12710) 2024-05-01 17:19:20 -05:00
nu_plugin_inc Bump version to 0.93.1 (#12710) 2024-05-01 17:19:20 -05:00
nu_plugin_nu_example Bump version to 0.93.1 (#12710) 2024-05-01 17:19:20 -05:00
nu_plugin_polars Replace ExternalStream with new ByteStream type (#12774) 2024-05-16 07:11:18 -07:00
nu_plugin_python Bump version to 0.93.1 (#12710) 2024-05-01 17:19:20 -05:00
nu_plugin_query Bump version to 0.93.1 (#12710) 2024-05-01 17:19:20 -05:00
nu_plugin_stress_internals Upgrade to interprocess 2.0.0 (#12729) 2024-05-02 22:31:33 -07:00
nuon Shrink Value by boxing Range/Closure (#12784) 2024-05-09 08:10:58 +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.