Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion library/std/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,57 @@ impl fmt::Debug for SplitPaths<'_> {
}
}

/// An iterator that splits an environment variable into paths according to
/// platform-specific conventions.
///
/// The iterator element type is <code>&[Path]</code>.
///
/// This structure is created by [`env::split_paths_ref()`]. See its
/// documentation for more.
///
/// [`env::split_paths_ref()`]: split_paths_ref
#[must_use = "iterators are lazy and do nothing unless consumed"]
#[unstable(feature = "env_split_paths_ref", issue = "none")]
pub struct SplitPathsRef<'a> {
inner: paths_imp::SplitPathsRef<'a>,
}

/// Parses input according to platform conventions for the `PATH`
/// environment variable.
///
/// Unlike [`split_paths`], this function does not allocate and instead yields
/// [`Path`]s borrowed from `unparsed`. Returns `None` on platforms that may
/// require allocations to handle `PATH` splitting conventions.
///
/// # Platform-specific behavior
///
/// Returns `Some` on Unix platforms and `None` on all other platforms.
/// Note that this [may change in the future][changes].
///
/// [changes]: io#platform-specific-behavior
#[unstable(feature = "env_split_paths_ref", issue = "none")]
pub fn split_paths_ref<T: AsRef<OsStr> + ?Sized>(unparsed: &T) -> Option<SplitPathsRef<'_>> {
Some(SplitPathsRef { inner: paths_imp::split_paths_ref(unparsed.as_ref())? })
}

#[unstable(feature = "env_split_paths_ref", issue = "none")]
impl<'a> Iterator for SplitPathsRef<'a> {
type Item = &'a Path;
fn next(&mut self) -> Option<&'a Path> {
self.inner.next()
}
fn size_hint(&self) -> (usize, Option<usize>) {
self.inner.size_hint()
}
}

#[unstable(feature = "env_split_paths_ref", issue = "none")]
impl fmt::Debug for SplitPathsRef<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("SplitPathsRef").finish_non_exhaustive()
}
}

/// The error type for operations on the `PATH` variable. Possibly returned from
/// [`env::join_paths()`].
///
Expand Down Expand Up @@ -606,7 +657,6 @@ impl Error for JoinPathsError {
/// For example, [XDG Base Directories] on Unix or the `LOCALAPPDATA` and `APPDATA` environment variables on Windows.
///
/// [XDG Base Directories]: https://specifications.freedesktop.org/basedir-spec/latest/
// feature(xdg_basedir): This should link to std::os::unix::xdg once it's stabilized
///
/// # Unix
///
Expand Down
7 changes: 7 additions & 0 deletions library/std/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ use crate::sys::{AsInner, AsInnerMut, FromInner, IntoInner, fs as fs_imp};
use crate::time::SystemTime;
use crate::{error, fmt};

pub(crate) mod dirs;

#[unstable(feature = "fs_home_dirs", issue = "162082")]
pub use self::dirs::HomeDirs;
#[unstable(feature = "fs_media_dirs", issue = "162083")]
pub use self::dirs::MediaDirs;

/// An object providing access to an open file on the filesystem.
///
/// An instance of a `File` can be read and/or written depending on what options
Expand Down
Loading
Loading