Skip to content

Commit da470e7

Browse files
committed
Amend RFC 517: Add material on std::env
1 parent e0999be commit da470e7

File tree

1 file changed

+67
-2
lines changed

1 file changed

+67
-2
lines changed

text/0517-io-os-reform.md

+67-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ follow-up PRs against this RFC.
4949
* [Modules]
5050
* [core::io] (stub)
5151
* [The std::io facade] (stub)
52-
* [std::env] (stub)
52+
* [std::env]
5353
* [std::fs] (stub)
5454
* [std::net] (stub)
5555
* [std::process] (stub)
@@ -483,7 +483,72 @@ throughout IO, we can go on to explore the modules in detail.
483483
### `std::env`
484484
[std::env]: #stdenv
485485

486-
> To be added in a follow-up PR.
486+
Most of what's available in `std::os` today will move to `std::env`,
487+
and the signatures will be updated to follow this RFC's
488+
[Design principles] as follows.
489+
490+
**Arguments**:
491+
492+
* `args`: change to yield an iterator rather than vector if possible; in any case, it should produce an `OsStrBuf`.
493+
494+
**Environment variables**:
495+
496+
* `vars` (renamed from `env`): yields a vector of `(OsStrBuf, OsStrBuf)` pairs.
497+
* `var` (renamed from `getenv`): take a value bounded by `IntoOsStrBuf`,
498+
allowing Rust strings and slices to be ergonomically passed in. Yields an `Option<OsStrBuf>`.
499+
* `set_var` (renamed from `setenv`): takes two `IntoOsStrBuf`-bounded values.
500+
* `remove_var` (renamed from `unsetenv`): takes a `IntoOsStrBuf`-bounded value.
501+
502+
* `join_paths`: take an `IntoIterator<T>` where `T: IntoOsStrBuf`, yield a `Result<OsStrBuf, JoinPathsError>`.
503+
* `split_paths` take a `IntoOsStrBuf`, yield an `Iterator<Path>`.
504+
505+
**Working directory**:
506+
507+
* `current_dir` (renamed from `getcwd`): yields a `PathBuf`.
508+
* `set_current_dir` (renamed from `change_dir`): takes an `AsPath` value.
509+
510+
**Important locations**:
511+
512+
* `home_dir` (renamed from `homedir`): returns home directory as a `PathBuf`
513+
* `temp_dir` (renamed from `tmpdir`): returns a temporary directly as a `PathBuf`
514+
* `current_exe` (renamed from `self_exe_name`): returns the full path
515+
to the current binary as a `PathBuf`.
516+
517+
**Exit status**:
518+
519+
* `get_exit_status` and `set_exit_status` stay as they are, but with
520+
updated docs that reflect that these only affect the return value of
521+
`std::rt::start`.
522+
523+
**Architecture information**:
524+
525+
* `num_cpus`, `page_size`: stay as they are
526+
527+
**Constants**:
528+
529+
* Stabilize `ARCH`, `DLL_PREFIX`, `DLL_EXTENSION`, `DLL_SUFFIX`, `EXE_EXTENSION`, `EXE_SUFFIX`, `FAMILY` as they are.
530+
* Rename `SYSNAME` to `OS`.
531+
* Remove `TMPBUF_SZ`.
532+
533+
This brings the constants into line with our naming conventions elsewhere.
534+
535+
#### Items to move to `os::platform`
536+
537+
* `pipe` will move to `os::unix`. It is currently primarily used for
538+
hooking to the IO of a child process, which will now be done behind
539+
a trait object abstraction.
540+
541+
#### Removed items
542+
543+
* `errno`, `error_string` and `last_os_error` provide redundant,
544+
platform-specific functionality and will be removed for now. They
545+
may reappear later in `os::unix` and `os::windows` in a modified
546+
form.
547+
* `dll_filename`: deprecated in favor of working directly with the constants.
548+
* `_NSGetArgc`, `_NSGetArgv`: these should never have been public.
549+
* `self_exe_path`: deprecated in favor of `current_exe` plus path operations.
550+
* `make_absolute`: deprecated in favor of explicitly joining with the working directory.
551+
* all `_as_bytes` variants: deprecated in favor of yielding `OsStrBuf` values
487552

488553
### `std::fs`
489554
[std::fs]: #stdfs

0 commit comments

Comments
 (0)