Skip to content

std: Generalize generics a bit in std::env #25135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 6, 2015
Merged
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
12 changes: 5 additions & 7 deletions src/libstd/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub fn current_dir() -> io::Result<PathBuf> {
/// println!("Successfully changed working directory to {}!", root.display());
/// ```
#[stable(feature = "env", since = "1.0.0")]
pub fn set_current_dir<P: AsRef<Path> + ?Sized>(p: &P) -> io::Result<()> {
pub fn set_current_dir<P: AsRef<Path>>(p: P) -> io::Result<()> {
os_imp::chdir(p.as_ref())
}

Expand Down Expand Up @@ -175,7 +175,7 @@ impl Iterator for VarsOs {
/// }
/// ```
#[stable(feature = "env", since = "1.0.0")]
pub fn var<K: ?Sized>(key: &K) -> Result<String, VarError> where K: AsRef<OsStr> {
pub fn var<K: AsRef<OsStr>>(key: K) -> Result<String, VarError> {
match var_os(key) {
Some(s) => s.into_string().map_err(VarError::NotUnicode),
None => Err(VarError::NotPresent)
Expand All @@ -197,7 +197,7 @@ pub fn var<K: ?Sized>(key: &K) -> Result<String, VarError> where K: AsRef<OsStr>
/// }
/// ```
#[stable(feature = "env", since = "1.0.0")]
pub fn var_os<K: ?Sized>(key: &K) -> Option<OsString> where K: AsRef<OsStr> {
pub fn var_os<K: AsRef<OsStr>>(key: K) -> Option<OsString> {
let _g = ENV_LOCK.lock();
os_imp::getenv(key.as_ref())
}
Expand Down Expand Up @@ -253,9 +253,7 @@ impl Error for VarError {
/// assert_eq!(env::var(key), Ok("VALUE".to_string()));
/// ```
#[stable(feature = "env", since = "1.0.0")]
pub fn set_var<K: ?Sized, V: ?Sized>(k: &K, v: &V)
where K: AsRef<OsStr>, V: AsRef<OsStr>
{
pub fn set_var<K: AsRef<OsStr>, V: AsRef<OsStr>>(k: K, v: V) {
let _g = ENV_LOCK.lock();
os_imp::setenv(k.as_ref(), v.as_ref())
}
Expand All @@ -275,7 +273,7 @@ pub fn set_var<K: ?Sized, V: ?Sized>(k: &K, v: &V)
/// assert!(env::var(key).is_err());
/// ```
#[stable(feature = "env", since = "1.0.0")]
pub fn remove_var<K: ?Sized>(k: &K) where K: AsRef<OsStr> {
pub fn remove_var<K: AsRef<OsStr>>(k: K) {
let _g = ENV_LOCK.lock();
os_imp::unsetenv(k.as_ref())
}
Expand Down