1 //! Inspection and manipulation of the process's environment.
3 //! This module contains functions to inspect various aspects such as
4 //! environment variables, process arguments, the current directory, and various
5 //! other important directories.
7 //! There are several functions and structs in this module that have a
8 //! counterpart ending in `os`. Those ending in `os` will return an [`OsString`]
9 //! and those without will return a [`String`].
11 #![stable(feature = "env", since = "1.0.0")]
16 use crate::error::Error;
17 use crate::ffi::{OsStr, OsString};
20 use crate::path::{Path, PathBuf};
22 use crate::sys::os as os_imp;
24 /// Returns the current working directory as a [`PathBuf`].
26 /// # Platform-specific behavior
28 /// This function [currently] corresponds to the `getcwd` function on Unix
29 /// and the `GetCurrentDirectoryW` function on Windows.
31 /// [currently]: crate::io#platform-specific-behavior
35 /// Returns an [`Err`] if the current working directory value is invalid.
38 /// * Current directory does not exist.
39 /// * There are insufficient permissions to access the current directory.
46 /// fn main() -> std::io::Result<()> {
47 /// let path = env::current_dir()?;
48 /// println!("The current directory is {}", path.display());
53 #[doc(alias = "getcwd")]
54 #[doc(alias = "GetCurrentDirectory")]
55 #[stable(feature = "env", since = "1.0.0")]
56 pub fn current_dir() -> io::Result<PathBuf> {
60 /// Changes the current working directory to the specified path.
62 /// # Platform-specific behavior
64 /// This function [currently] corresponds to the `chdir` function on Unix
65 /// and the `SetCurrentDirectoryW` function on Windows.
67 /// Returns an [`Err`] if the operation fails.
69 /// [currently]: crate::io#platform-specific-behavior
75 /// use std::path::Path;
77 /// let root = Path::new("/");
78 /// assert!(env::set_current_dir(&root).is_ok());
79 /// println!("Successfully changed working directory to {}!", root.display());
81 #[doc(alias = "chdir")]
82 #[stable(feature = "env", since = "1.0.0")]
83 pub fn set_current_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
84 os_imp::chdir(path.as_ref())
87 /// An iterator over a snapshot of the environment variables of this process.
89 /// This structure is created by [`env::vars()`]. See its documentation for more.
91 /// [`env::vars()`]: vars
92 #[stable(feature = "env", since = "1.0.0")]
97 /// An iterator over a snapshot of the environment variables of this process.
99 /// This structure is created by [`env::vars_os()`]. See its documentation for more.
101 /// [`env::vars_os()`]: vars_os
102 #[stable(feature = "env", since = "1.0.0")]
107 /// Returns an iterator of (variable, value) pairs of strings, for all the
108 /// environment variables of the current process.
110 /// The returned iterator contains a snapshot of the process's environment
111 /// variables at the time of this invocation. Modifications to environment
112 /// variables afterwards will not be reflected in the returned iterator.
116 /// While iterating, the returned iterator will panic if any key or value in the
117 /// environment is not valid unicode. If this is not desired, consider using
118 /// [`env::vars_os()`].
125 /// // We will iterate through the references to the element returned by
127 /// for (key, value) in env::vars() {
128 /// println!("{key}: {value}");
132 /// [`env::vars_os()`]: vars_os
134 #[stable(feature = "env", since = "1.0.0")]
135 pub fn vars() -> Vars {
136 Vars { inner: vars_os() }
139 /// Returns an iterator of (variable, value) pairs of OS strings, for all the
140 /// environment variables of the current process.
142 /// The returned iterator contains a snapshot of the process's environment
143 /// variables at the time of this invocation. Modifications to environment
144 /// variables afterwards will not be reflected in the returned iterator.
146 /// Note that the returned iterator will not check if the environment variables
147 /// are valid Unicode. If you want to panic on invalid UTF-8,
148 /// use the [`vars`] function instead.
155 /// // We will iterate through the references to the element returned by
156 /// // env::vars_os();
157 /// for (key, value) in env::vars_os() {
158 /// println!("{key:?}: {value:?}");
162 #[stable(feature = "env", since = "1.0.0")]
163 pub fn vars_os() -> VarsOs {
164 VarsOs { inner: os_imp::env() }
167 #[stable(feature = "env", since = "1.0.0")]
168 impl Iterator for Vars {
169 type Item = (String, String);
170 fn next(&mut self) -> Option<(String, String)> {
171 self.inner.next().map(|(a, b)| (a.into_string().unwrap(), b.into_string().unwrap()))
173 fn size_hint(&self) -> (usize, Option<usize>) {
174 self.inner.size_hint()
178 #[stable(feature = "std_debug", since = "1.16.0")]
179 impl fmt::Debug for Vars {
180 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
181 f.debug_struct("Vars").finish_non_exhaustive()
185 #[stable(feature = "env", since = "1.0.0")]
186 impl Iterator for VarsOs {
187 type Item = (OsString, OsString);
188 fn next(&mut self) -> Option<(OsString, OsString)> {
191 fn size_hint(&self) -> (usize, Option<usize>) {
192 self.inner.size_hint()
196 #[stable(feature = "std_debug", since = "1.16.0")]
197 impl fmt::Debug for VarsOs {
198 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
199 f.debug_struct("VarOs").finish_non_exhaustive()
203 /// Fetches the environment variable `key` from the current process.
207 /// This function will return an error if the environment variable isn't set.
209 /// This function may return an error if the environment variable's name contains
210 /// the equal sign character (`=`) or the NUL character.
212 /// This function will return an error if the environment variable's value is
213 /// not valid Unicode. If this is not desired, consider using [`var_os`].
220 /// let key = "HOME";
221 /// match env::var(key) {
222 /// Ok(val) => println!("{key}: {val:?}"),
223 /// Err(e) => println!("couldn't interpret {key}: {e}"),
226 #[stable(feature = "env", since = "1.0.0")]
227 pub fn var<K: AsRef<OsStr>>(key: K) -> Result<String, VarError> {
231 fn _var(key: &OsStr) -> Result<String, VarError> {
233 Some(s) => s.into_string().map_err(VarError::NotUnicode),
234 None => Err(VarError::NotPresent),
238 /// Fetches the environment variable `key` from the current process, returning
239 /// [`None`] if the variable isn't set or there's another error.
241 /// Note that the method will not check if the environment variable
242 /// is valid Unicode. If you want to have an error on invalid UTF-8,
243 /// use the [`var`] function instead.
247 /// This function returns an error if the environment variable isn't set.
249 /// This function may return an error if the environment variable's name contains
250 /// the equal sign character (`=`) or the NUL character.
252 /// This function may return an error if the environment variable's value contains
253 /// the NUL character.
260 /// let key = "HOME";
261 /// match env::var_os(key) {
262 /// Some(val) => println!("{key}: {val:?}"),
263 /// None => println!("{key} is not defined in the environment.")
267 #[stable(feature = "env", since = "1.0.0")]
268 pub fn var_os<K: AsRef<OsStr>>(key: K) -> Option<OsString> {
269 _var_os(key.as_ref())
272 fn _var_os(key: &OsStr) -> Option<OsString> {
276 /// The error type for operations interacting with environment variables.
277 /// Possibly returned from [`env::var()`].
279 /// [`env::var()`]: var
280 #[derive(Debug, PartialEq, Eq, Clone)]
281 #[stable(feature = "env", since = "1.0.0")]
283 /// The specified environment variable was not present in the current
284 /// process's environment.
285 #[stable(feature = "env", since = "1.0.0")]
288 /// The specified environment variable was found, but it did not contain
289 /// valid unicode data. The found data is returned as a payload of this
291 #[stable(feature = "env", since = "1.0.0")]
292 NotUnicode(#[stable(feature = "env", since = "1.0.0")] OsString),
295 #[stable(feature = "env", since = "1.0.0")]
296 impl fmt::Display for VarError {
297 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
299 VarError::NotPresent => write!(f, "environment variable not found"),
300 VarError::NotUnicode(ref s) => {
301 write!(f, "environment variable was not valid unicode: {:?}", s)
307 #[stable(feature = "env", since = "1.0.0")]
308 impl Error for VarError {
310 fn description(&self) -> &str {
312 VarError::NotPresent => "environment variable not found",
313 VarError::NotUnicode(..) => "environment variable was not valid unicode",
318 /// Sets the environment variable `key` to the value `value` for the currently running
321 /// Note that while concurrent access to environment variables is safe in Rust,
322 /// some platforms only expose inherently unsafe non-threadsafe APIs for
323 /// inspecting the environment. As a result, extra care needs to be taken when
324 /// auditing calls to unsafe external FFI functions to ensure that any external
325 /// environment accesses are properly synchronized with accesses in Rust.
327 /// Discussion of this unsafety on Unix may be found in:
329 /// - [Austin Group Bugzilla](https://austingroupbugs.net/view.php?id=188)
330 /// - [GNU C library Bugzilla](https://sourceware.org/bugzilla/show_bug.cgi?id=15607#c2)
334 /// This function may panic if `key` is empty, contains an ASCII equals sign `'='`
335 /// or the NUL character `'\0'`, or when `value` contains the NUL character.
343 /// env::set_var(key, "VALUE");
344 /// assert_eq!(env::var(key), Ok("VALUE".to_string()));
346 #[stable(feature = "env", since = "1.0.0")]
347 pub fn set_var<K: AsRef<OsStr>, V: AsRef<OsStr>>(key: K, value: V) {
348 _set_var(key.as_ref(), value.as_ref())
351 fn _set_var(key: &OsStr, value: &OsStr) {
352 os_imp::setenv(key, value).unwrap_or_else(|e| {
353 panic!("failed to set environment variable `{key:?}` to `{value:?}`: {e}")
357 /// Removes an environment variable from the environment of the currently running process.
359 /// Note that while concurrent access to environment variables is safe in Rust,
360 /// some platforms only expose inherently unsafe non-threadsafe APIs for
361 /// inspecting the environment. As a result extra care needs to be taken when
362 /// auditing calls to unsafe external FFI functions to ensure that any external
363 /// environment accesses are properly synchronized with accesses in Rust.
365 /// Discussion of this unsafety on Unix may be found in:
367 /// - [Austin Group Bugzilla](https://austingroupbugs.net/view.php?id=188)
368 /// - [GNU C library Bugzilla](https://sourceware.org/bugzilla/show_bug.cgi?id=15607#c2)
372 /// This function may panic if `key` is empty, contains an ASCII equals sign
373 /// `'='` or the NUL character `'\0'`, or when the value contains the NUL
382 /// env::set_var(key, "VALUE");
383 /// assert_eq!(env::var(key), Ok("VALUE".to_string()));
385 /// env::remove_var(key);
386 /// assert!(env::var(key).is_err());
388 #[stable(feature = "env", since = "1.0.0")]
389 pub fn remove_var<K: AsRef<OsStr>>(key: K) {
390 _remove_var(key.as_ref())
393 fn _remove_var(key: &OsStr) {
394 os_imp::unsetenv(key)
395 .unwrap_or_else(|e| panic!("failed to remove environment variable `{key:?}`: {e}"))
398 /// An iterator that splits an environment variable into paths according to
399 /// platform-specific conventions.
401 /// The iterator element type is [`PathBuf`].
403 /// This structure is created by [`env::split_paths()`]. See its
404 /// documentation for more.
406 /// [`env::split_paths()`]: split_paths
407 #[must_use = "iterators are lazy and do nothing unless consumed"]
408 #[stable(feature = "env", since = "1.0.0")]
409 pub struct SplitPaths<'a> {
410 inner: os_imp::SplitPaths<'a>,
413 /// Parses input according to platform conventions for the `PATH`
414 /// environment variable.
416 /// Returns an iterator over the paths contained in `unparsed`. The iterator
417 /// element type is [`PathBuf`].
424 /// let key = "PATH";
425 /// match env::var_os(key) {
427 /// for path in env::split_paths(&paths) {
428 /// println!("'{}'", path.display());
431 /// None => println!("{key} is not defined in the environment.")
434 #[stable(feature = "env", since = "1.0.0")]
435 pub fn split_paths<T: AsRef<OsStr> + ?Sized>(unparsed: &T) -> SplitPaths<'_> {
436 SplitPaths { inner: os_imp::split_paths(unparsed.as_ref()) }
439 #[stable(feature = "env", since = "1.0.0")]
440 impl<'a> Iterator for SplitPaths<'a> {
442 fn next(&mut self) -> Option<PathBuf> {
445 fn size_hint(&self) -> (usize, Option<usize>) {
446 self.inner.size_hint()
450 #[stable(feature = "std_debug", since = "1.16.0")]
451 impl fmt::Debug for SplitPaths<'_> {
452 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
453 f.debug_struct("SplitPaths").finish_non_exhaustive()
457 /// The error type for operations on the `PATH` variable. Possibly returned from
458 /// [`env::join_paths()`].
460 /// [`env::join_paths()`]: join_paths
462 #[stable(feature = "env", since = "1.0.0")]
463 pub struct JoinPathsError {
464 inner: os_imp::JoinPathsError,
467 /// Joins a collection of [`Path`]s appropriately for the `PATH`
468 /// environment variable.
472 /// Returns an [`Err`] (containing an error message) if one of the input
473 /// [`Path`]s contains an invalid character for constructing the `PATH`
474 /// variable (a double quote on Windows or a colon on Unix).
478 /// Joining paths on a Unix-like platform:
482 /// use std::ffi::OsString;
483 /// use std::path::Path;
485 /// fn main() -> Result<(), env::JoinPathsError> {
486 /// # if cfg!(unix) {
487 /// let paths = [Path::new("/bin"), Path::new("/usr/bin")];
488 /// let path_os_string = env::join_paths(paths.iter())?;
489 /// assert_eq!(path_os_string, OsString::from("/bin:/usr/bin"));
495 /// Joining a path containing a colon on a Unix-like platform results in an
499 /// # if cfg!(unix) {
501 /// use std::path::Path;
503 /// let paths = [Path::new("/bin"), Path::new("/usr/bi:n")];
504 /// assert!(env::join_paths(paths.iter()).is_err());
508 /// Using `env::join_paths()` with [`env::split_paths()`] to append an item to
509 /// the `PATH` environment variable:
513 /// use std::path::PathBuf;
515 /// fn main() -> Result<(), env::JoinPathsError> {
516 /// if let Some(path) = env::var_os("PATH") {
517 /// let mut paths = env::split_paths(&path).collect::<Vec<_>>();
518 /// paths.push(PathBuf::from("/home/xyz/bin"));
519 /// let new_path = env::join_paths(paths)?;
520 /// env::set_var("PATH", &new_path);
527 /// [`env::split_paths()`]: split_paths
528 #[stable(feature = "env", since = "1.0.0")]
529 pub fn join_paths<I, T>(paths: I) -> Result<OsString, JoinPathsError>
531 I: IntoIterator<Item = T>,
534 os_imp::join_paths(paths.into_iter()).map_err(|e| JoinPathsError { inner: e })
537 #[stable(feature = "env", since = "1.0.0")]
538 impl fmt::Display for JoinPathsError {
539 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
544 #[stable(feature = "env", since = "1.0.0")]
545 impl Error for JoinPathsError {
546 #[allow(deprecated, deprecated_in_future)]
547 fn description(&self) -> &str {
548 self.inner.description()
552 /// Returns the path of the current user's home directory if known.
556 /// - Returns the value of the 'HOME' environment variable if it is set
557 /// (including to an empty string).
558 /// - Otherwise, it tries to determine the home directory by invoking the `getpwuid_r` function
559 /// using the UID of the current user. An empty home directory field returned from the
560 /// `getpwuid_r` function is considered to be a valid value.
561 /// - Returns `None` if the current user has no entry in the /etc/passwd file.
565 /// - Returns the value of the 'HOME' environment variable if it is set
566 /// (including to an empty string).
567 /// - Otherwise, returns the value of the 'USERPROFILE' environment variable if it is set
568 /// (including to an empty string).
569 /// - If both do not exist, [`GetUserProfileDirectory`][msdn] is used to return the path.
571 /// [msdn]: https://docs.microsoft.com/en-us/windows/win32/api/userenv/nf-userenv-getuserprofiledirectorya
575 /// This function is deprecated because the behaviour on Windows is not correct.
576 /// The 'HOME' environment variable is not standard on Windows, and may not produce
577 /// desired results; for instance, under Cygwin or Mingw it will return `/home/you`
578 /// when it should return `C:\Users\you`.
585 /// match env::home_dir() {
586 /// Some(path) => println!("Your home directory, probably: {}", path.display()),
587 /// None => println!("Impossible to get your home dir!"),
592 note = "This function's behavior may be unexpected on Windows. \
593 Consider using a crate from crates.io instead."
596 #[stable(feature = "env", since = "1.0.0")]
597 pub fn home_dir() -> Option<PathBuf> {
601 /// Returns the path of a temporary directory.
603 /// The temporary directory may be shared among users, or between processes
604 /// with different privileges; thus, the creation of any files or directories
605 /// in the temporary directory must use a secure method to create a uniquely
606 /// named file. Creating a file or directory with a fixed or predictable name
607 /// may result in "insecure temporary file" security vulnerabilities. Consider
608 /// using a crate that securely creates temporary files or directories.
610 /// # Platform-specific behavior
612 /// On Unix, returns the value of the `TMPDIR` environment variable if it is
613 /// set, otherwise for non-Android it returns `/tmp`. On Android, since there
614 /// is no global temporary folder (it is usually allocated per-app), it returns
615 /// `/data/local/tmp`.
616 /// On Windows, the behavior is equivalent to that of [`GetTempPath2`][GetTempPath2] /
617 /// [`GetTempPath`][GetTempPath], which this function uses internally.
618 /// Note that, this [may change in the future][changes].
620 /// [changes]: io#platform-specific-behavior
621 /// [GetTempPath2]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettemppath2a
622 /// [GetTempPath]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettemppatha
628 /// let dir = env::temp_dir();
629 /// println!("Temporary directory: {}", dir.display());
633 #[stable(feature = "env", since = "1.0.0")]
634 pub fn temp_dir() -> PathBuf {
638 /// Returns the full filesystem path of the current running executable.
640 /// # Platform-specific behavior
642 /// If the executable was invoked through a symbolic link, some platforms will
643 /// return the path of the symbolic link and other platforms will return the
644 /// path of the symbolic link’s target.
646 /// If the executable is renamed while it is running, platforms may return the
647 /// path at the time it was loaded instead of the new path.
651 /// Acquiring the path of the current executable is a platform-specific operation
652 /// that can fail for a good number of reasons. Some errors can include, but not
653 /// be limited to, filesystem operations failing or general syscall failures.
657 /// The output of this function should not be trusted for anything
658 /// that might have security implications. Basically, if users can run
659 /// the executable, they can change the output arbitrarily.
661 /// As an example, you can easily introduce a race condition. It goes
664 /// 1. You get the path to the current executable using `current_exe()`, and
665 /// store it in a variable.
666 /// 2. Time passes. A malicious actor removes the current executable, and
667 /// replaces it with a malicious one.
668 /// 3. You then use the stored path to re-execute the current
671 /// You expected to safely execute the current executable, but you're
672 /// instead executing something completely different. The code you
673 /// just executed run with your privileges.
675 /// This sort of behavior has been known to [lead to privilege escalation] when
676 /// used incorrectly.
678 /// [lead to privilege escalation]: https://securityvulns.com/Wdocument183.html
685 /// match env::current_exe() {
686 /// Ok(exe_path) => println!("Path of this executable is: {}",
687 /// exe_path.display()),
688 /// Err(e) => println!("failed to get current exe path: {e}"),
691 #[stable(feature = "env", since = "1.0.0")]
692 pub fn current_exe() -> io::Result<PathBuf> {
693 os_imp::current_exe()
696 /// An iterator over the arguments of a process, yielding a [`String`] value for
699 /// This struct is created by [`env::args()`]. See its documentation
702 /// The first element is traditionally the path of the executable, but it can be
703 /// set to arbitrary text, and might not even exist. This means this property
704 /// should not be relied upon for security purposes.
706 /// [`env::args()`]: args
707 #[must_use = "iterators are lazy and do nothing unless consumed"]
708 #[stable(feature = "env", since = "1.0.0")]
713 /// An iterator over the arguments of a process, yielding an [`OsString`] value
714 /// for each argument.
716 /// This struct is created by [`env::args_os()`]. See its documentation
719 /// The first element is traditionally the path of the executable, but it can be
720 /// set to arbitrary text, and might not even exist. This means this property
721 /// should not be relied upon for security purposes.
723 /// [`env::args_os()`]: args_os
724 #[must_use = "iterators are lazy and do nothing unless consumed"]
725 #[stable(feature = "env", since = "1.0.0")]
727 inner: sys::args::Args,
730 /// Returns the arguments that this program was started with (normally passed
731 /// via the command line).
733 /// The first element is traditionally the path of the executable, but it can be
734 /// set to arbitrary text, and might not even exist. This means this property should
735 /// not be relied upon for security purposes.
737 /// On Unix systems the shell usually expands unquoted arguments with glob patterns
738 /// (such as `*` and `?`). On Windows this is not done, and such arguments are
741 /// On glibc Linux systems, arguments are retrieved by placing a function in `.init_array`.
742 /// glibc passes `argc`, `argv`, and `envp` to functions in `.init_array`, as a non-standard
743 /// extension. This allows `std::env::args` to work even in a `cdylib` or `staticlib`, as it
744 /// does on macOS and Windows.
748 /// The returned iterator will panic during iteration if any argument to the
749 /// process is not valid Unicode. If this is not desired,
750 /// use the [`args_os`] function instead.
757 /// // Prints each argument on a separate line
758 /// for argument in env::args() {
759 /// println!("{argument}");
762 #[stable(feature = "env", since = "1.0.0")]
763 pub fn args() -> Args {
764 Args { inner: args_os() }
767 /// Returns the arguments that this program was started with (normally passed
768 /// via the command line).
770 /// The first element is traditionally the path of the executable, but it can be
771 /// set to arbitrary text, and might not even exist. This means this property should
772 /// not be relied upon for security purposes.
774 /// On Unix systems the shell usually expands unquoted arguments with glob patterns
775 /// (such as `*` and `?`). On Windows this is not done, and such arguments are
778 /// On glibc Linux systems, arguments are retrieved by placing a function in `.init_array`.
779 /// glibc passes `argc`, `argv`, and `envp` to functions in `.init_array`, as a non-standard
780 /// extension. This allows `std::env::args_os` to work even in a `cdylib` or `staticlib`, as it
781 /// does on macOS and Windows.
783 /// Note that the returned iterator will not check if the arguments to the
784 /// process are valid Unicode. If you want to panic on invalid UTF-8,
785 /// use the [`args`] function instead.
792 /// // Prints each argument on a separate line
793 /// for argument in env::args_os() {
794 /// println!("{argument:?}");
797 #[stable(feature = "env", since = "1.0.0")]
798 pub fn args_os() -> ArgsOs {
799 ArgsOs { inner: sys::args::args() }
802 #[stable(feature = "env_unimpl_send_sync", since = "1.26.0")]
803 impl !Send for Args {}
805 #[stable(feature = "env_unimpl_send_sync", since = "1.26.0")]
806 impl !Sync for Args {}
808 #[stable(feature = "env", since = "1.0.0")]
809 impl Iterator for Args {
811 fn next(&mut self) -> Option<String> {
812 self.inner.next().map(|s| s.into_string().unwrap())
814 fn size_hint(&self) -> (usize, Option<usize>) {
815 self.inner.size_hint()
819 #[stable(feature = "env", since = "1.0.0")]
820 impl ExactSizeIterator for Args {
821 fn len(&self) -> usize {
824 fn is_empty(&self) -> bool {
825 self.inner.is_empty()
829 #[stable(feature = "env_iterators", since = "1.12.0")]
830 impl DoubleEndedIterator for Args {
831 fn next_back(&mut self) -> Option<String> {
832 self.inner.next_back().map(|s| s.into_string().unwrap())
836 #[stable(feature = "std_debug", since = "1.16.0")]
837 impl fmt::Debug for Args {
838 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
839 f.debug_struct("Args").field("inner", &self.inner.inner).finish()
843 #[stable(feature = "env_unimpl_send_sync", since = "1.26.0")]
844 impl !Send for ArgsOs {}
846 #[stable(feature = "env_unimpl_send_sync", since = "1.26.0")]
847 impl !Sync for ArgsOs {}
849 #[stable(feature = "env", since = "1.0.0")]
850 impl Iterator for ArgsOs {
851 type Item = OsString;
852 fn next(&mut self) -> Option<OsString> {
855 fn size_hint(&self) -> (usize, Option<usize>) {
856 self.inner.size_hint()
860 #[stable(feature = "env", since = "1.0.0")]
861 impl ExactSizeIterator for ArgsOs {
862 fn len(&self) -> usize {
865 fn is_empty(&self) -> bool {
866 self.inner.is_empty()
870 #[stable(feature = "env_iterators", since = "1.12.0")]
871 impl DoubleEndedIterator for ArgsOs {
872 fn next_back(&mut self) -> Option<OsString> {
873 self.inner.next_back()
877 #[stable(feature = "std_debug", since = "1.16.0")]
878 impl fmt::Debug for ArgsOs {
879 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
880 f.debug_struct("ArgsOs").field("inner", &self.inner).finish()
884 /// Constants associated with the current target
885 #[stable(feature = "env", since = "1.0.0")]
887 use crate::sys::env::os;
889 /// A string describing the architecture of the CPU that is currently
892 /// Some possible values:
906 #[stable(feature = "env", since = "1.0.0")]
907 pub const ARCH: &str = env!("STD_ENV_ARCH");
909 /// The family of the operating system. Example value is `unix`.
911 /// Some possible values:
915 #[stable(feature = "env", since = "1.0.0")]
916 pub const FAMILY: &str = os::FAMILY;
918 /// A string describing the specific operating system in use.
919 /// Example value is `linux`.
921 /// Some possible values:
933 #[stable(feature = "env", since = "1.0.0")]
934 pub const OS: &str = os::OS;
936 /// Specifies the filename prefix used for shared libraries on this
937 /// platform. Example value is `lib`.
939 /// Some possible values:
942 /// - `""` (an empty string)
943 #[stable(feature = "env", since = "1.0.0")]
944 pub const DLL_PREFIX: &str = os::DLL_PREFIX;
946 /// Specifies the filename suffix used for shared libraries on this
947 /// platform. Example value is `.so`.
949 /// Some possible values:
954 #[stable(feature = "env", since = "1.0.0")]
955 pub const DLL_SUFFIX: &str = os::DLL_SUFFIX;
957 /// Specifies the file extension used for shared libraries on this
958 /// platform that goes after the dot. Example value is `so`.
960 /// Some possible values:
965 #[stable(feature = "env", since = "1.0.0")]
966 pub const DLL_EXTENSION: &str = os::DLL_EXTENSION;
968 /// Specifies the filename suffix used for executable binaries on this
969 /// platform. Example value is `.exe`.
971 /// Some possible values:
976 /// - `""` (an empty string)
977 #[stable(feature = "env", since = "1.0.0")]
978 pub const EXE_SUFFIX: &str = os::EXE_SUFFIX;
980 /// Specifies the file extension, if any, used for executable binaries
981 /// on this platform. Example value is `exe`.
983 /// Some possible values:
986 /// - `""` (an empty string)
987 #[stable(feature = "env", since = "1.0.0")]
988 pub const EXE_EXTENSION: &str = os::EXE_EXTENSION;