From 9b88cd1c691626bb38c243c1996d1d2d045bbeda Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 5 May 2015 16:06:21 -0700 Subject: [PATCH] std: Generalize generics a bit in std::env Many bounds are currently of the form `T: ?Sized + AsRef` where the argument is `&T`, but the pattern elsewhere (primarily `std::fs`) has been to remove the `?Sized` bound and take `T` instead (allowing usage with both references and owned values). This commit generalizes the possible apis in `std::env` from `&T` to `T` in this fashion. The `split_paths` function remains the same as the return value borrows the input value, so ta borrowed reference is required. --- src/libstd/env.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/libstd/env.rs b/src/libstd/env.rs index facf33de6bb63..fe379208774a5 100644 --- a/src/libstd/env.rs +++ b/src/libstd/env.rs @@ -66,7 +66,7 @@ pub fn current_dir() -> io::Result { /// println!("Successfully changed working directory to {}!", root.display()); /// ``` #[stable(feature = "env", since = "1.0.0")] -pub fn set_current_dir + ?Sized>(p: &P) -> io::Result<()> { +pub fn set_current_dir>(p: P) -> io::Result<()> { os_imp::chdir(p.as_ref()) } @@ -175,7 +175,7 @@ impl Iterator for VarsOs { /// } /// ``` #[stable(feature = "env", since = "1.0.0")] -pub fn var(key: &K) -> Result where K: AsRef { +pub fn var>(key: K) -> Result { match var_os(key) { Some(s) => s.into_string().map_err(VarError::NotUnicode), None => Err(VarError::NotPresent) @@ -197,7 +197,7 @@ pub fn var(key: &K) -> Result where K: AsRef /// } /// ``` #[stable(feature = "env", since = "1.0.0")] -pub fn var_os(key: &K) -> Option where K: AsRef { +pub fn var_os>(key: K) -> Option { let _g = ENV_LOCK.lock(); os_imp::getenv(key.as_ref()) } @@ -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: &K, v: &V) - where K: AsRef, V: AsRef -{ +pub fn set_var, V: AsRef>(k: K, v: V) { let _g = ENV_LOCK.lock(); os_imp::setenv(k.as_ref(), v.as_ref()) } @@ -275,7 +273,7 @@ pub fn set_var(k: &K, v: &V) /// assert!(env::var(key).is_err()); /// ``` #[stable(feature = "env", since = "1.0.0")] -pub fn remove_var(k: &K) where K: AsRef { +pub fn remove_var>(k: K) { let _g = ENV_LOCK.lock(); os_imp::unsetenv(k.as_ref()) }