nushell/crates/nu-std
Douglas 2a3805c164
Virtual std module subdirectories (#14040)
# Description

Uses "normal" module `std/<submodule>/mod.nu` instead of renaming the
files (as requested in #13842).

# User-Facing Changes

No user-facing changes other than in `view files` results. Imports
remain the same after this PR.

# Tests + Formatting

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

Also manually confirmed that it does not interfere with nupm, since we
did have a conflict at one point (and it's not possible to test here).

# Performance Tests

## Linux

### Nushell Startup - No config

```nu
bench --pretty -n 200  { <path_to>/nu -c "exit" }
```

| Release | Startup Time |
| --- | --- |
| 0.98.0 | 22ms 730µs 768ns +/- 1ms 515µs 942ns
| This commit | 9ms 312µs 68ns +/- 709µs 378ns
| Yesterday's nightly | 9ms 230µs 953ns +/- 9ms 67µs 689ns

### Nushell Startup - Load full standard library

Measures relative impact of a full `use std *`, which isn't recommended,
but worth tracking.

```nu
bench --pretty -n 200  { <path_to>/nu -c "use std *; exit" }
```

| Release | Startup Time |
| --- | --- |
| 0.98.0 | 23ms 10µs 636ns +/- 1ms 277µs 854ns
| This commit | 26ms 922µs 769ns +/- 562µs 538ns
| Yesterday's nightly | 28ms 133µs 95ns +/- 761µs 943ns
| `deprecated_dirs` removal PR * | 23ms 610µs 333ns +/- 369µs 436ns

\* Current increase is partially due to double-loading `dirs` with
removal warning in older version.

# After Submitting

Still TODO - Update standard library doc
2024-10-10 06:56:37 -05:00
..
src Virtual std module subdirectories (#14040) 2024-10-10 06:56:37 -05:00
std Virtual std module subdirectories (#14040) 2024-10-10 06:56:37 -05:00
tests Fix dirs removal warning (#14029) 2024-10-09 08:03:33 -05:00
Cargo.toml Bump version to 0.98.1 (#13896) 2024-09-22 12:41:44 +08:00
CONTRIBUTING.md Surprising symlink resolution for std path add (#13258) 2024-06-28 18:11:48 -05:00
LICENSE add LICENSE to nu-std (#8803) 2023-04-07 13:39:21 -07:00
README.md Change the usage misnomer to "description" (#13598) 2024-08-22 12:02:08 +02:00
testing.nu Improves startup time when using std-lib (#13842) 2024-10-03 06:28:22 -05:00

Welcome to the standard library of `nushell`!

The standard library is a pure-nushell collection of custom commands which provide interactive utilities and building blocks for users writing casual scripts or complex applications.

To see what's here:

> use std
> scope commands | select name description | where name =~ "std "
#┬───────────name────────────┬───────────────────description───────────────────
0│std assert                 │Universal assert command
1│std assert equal           │Assert $left == $right
2│std assert error           │Assert that executing the code generates an error
3│std assert greater         │Assert $left > $right
4│std assert greater or equal│Assert $left >= $right
             ...                                     ...
─┴───────────────────────────┴─────────────────────────────────────────────────

🧰 Using the standard library in the REPL or in scripts

All commands in the standard library must be "imported" into the running environment (the interactive read-execute-print-loop (REPL) or a .nu script) using the use command.

You can choose to import the whole module, but then must refer to individual commands with a std prefix, e.g:

use std

std log debug "Running now"
std assert (1 == 2)

Or you can enumerate the specific commands you want to import and invoke them without the std prefix.

use std ["log debug" assert]

log debug "Running again"
assert (2 == 1)

This is probably the form of import you'll want to add to your env.nu for interactive use.

✏️ contribute to the standard library

You're invited to contribute to the standard library! See CONTRIBUTING.md for details