Skip to content

Commit 9b88cd1

Browse files
committed
std: Generalize generics a bit in std::env
Many bounds are currently of the form `T: ?Sized + AsRef<OsStr>` 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.
1 parent 6cd7486 commit 9b88cd1

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/libstd/env.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub fn current_dir() -> io::Result<PathBuf> {
6666
/// println!("Successfully changed working directory to {}!", root.display());
6767
/// ```
6868
#[stable(feature = "env", since = "1.0.0")]
69-
pub fn set_current_dir<P: AsRef<Path> + ?Sized>(p: &P) -> io::Result<()> {
69+
pub fn set_current_dir<P: AsRef<Path>>(p: P) -> io::Result<()> {
7070
os_imp::chdir(p.as_ref())
7171
}
7272

@@ -175,7 +175,7 @@ impl Iterator for VarsOs {
175175
/// }
176176
/// ```
177177
#[stable(feature = "env", since = "1.0.0")]
178-
pub fn var<K: ?Sized>(key: &K) -> Result<String, VarError> where K: AsRef<OsStr> {
178+
pub fn var<K: AsRef<OsStr>>(key: K) -> Result<String, VarError> {
179179
match var_os(key) {
180180
Some(s) => s.into_string().map_err(VarError::NotUnicode),
181181
None => Err(VarError::NotPresent)
@@ -197,7 +197,7 @@ pub fn var<K: ?Sized>(key: &K) -> Result<String, VarError> where K: AsRef<OsStr>
197197
/// }
198198
/// ```
199199
#[stable(feature = "env", since = "1.0.0")]
200-
pub fn var_os<K: ?Sized>(key: &K) -> Option<OsString> where K: AsRef<OsStr> {
200+
pub fn var_os<K: AsRef<OsStr>>(key: K) -> Option<OsString> {
201201
let _g = ENV_LOCK.lock();
202202
os_imp::getenv(key.as_ref())
203203
}
@@ -253,9 +253,7 @@ impl Error for VarError {
253253
/// assert_eq!(env::var(key), Ok("VALUE".to_string()));
254254
/// ```
255255
#[stable(feature = "env", since = "1.0.0")]
256-
pub fn set_var<K: ?Sized, V: ?Sized>(k: &K, v: &V)
257-
where K: AsRef<OsStr>, V: AsRef<OsStr>
258-
{
256+
pub fn set_var<K: AsRef<OsStr>, V: AsRef<OsStr>>(k: K, v: V) {
259257
let _g = ENV_LOCK.lock();
260258
os_imp::setenv(k.as_ref(), v.as_ref())
261259
}
@@ -275,7 +273,7 @@ pub fn set_var<K: ?Sized, V: ?Sized>(k: &K, v: &V)
275273
/// assert!(env::var(key).is_err());
276274
/// ```
277275
#[stable(feature = "env", since = "1.0.0")]
278-
pub fn remove_var<K: ?Sized>(k: &K) where K: AsRef<OsStr> {
276+
pub fn remove_var<K: AsRef<OsStr>>(k: K) {
279277
let _g = ENV_LOCK.lock();
280278
os_imp::unsetenv(k.as_ref())
281279
}

0 commit comments

Comments
 (0)