std: Remove ?Sized bounds from many I/O functions
It is a frequent pattern among I/O functions to take `P: AsPath + ?Sized` or `AsOsStr` instead of `AsPath`. Most of these functions do not need to take ownership of their argument, but for libraries in general it's much more ergonomic to not deal with `?Sized` at all and simply require an argument `P` instead of `&P`. This change is aimed at removing unsightly `?Sized` bounds while retaining the same level of usability as before. All affected functions now take ownership of their arguments instead of taking them by reference, but due to the forwarding implementations of `AsOsStr` and `AsPath` all code should continue to work as it did before. This is strictly speaking a breaking change due to the signatures of these functions changing, but normal idiomatic usage of these APIs should not break in practice. [breaking-change]
This commit is contained in:
parent
66853af9af
commit
60a4a2db88
4 changed files with 39 additions and 43 deletions
|
@ -147,7 +147,7 @@ impl Command {
|
|||
/// Builder methods are provided to change these defaults and
|
||||
/// otherwise configure the process.
|
||||
#[stable(feature = "process", since = "1.0.0")]
|
||||
pub fn new<S: AsOsStr + ?Sized>(program: &S) -> Command {
|
||||
pub fn new<S: AsOsStr>(program: S) -> Command {
|
||||
Command {
|
||||
inner: CommandImp::new(program.as_os_str()),
|
||||
stdin: None,
|
||||
|
@ -158,7 +158,7 @@ impl Command {
|
|||
|
||||
/// Add an argument to pass to the program.
|
||||
#[stable(feature = "process", since = "1.0.0")]
|
||||
pub fn arg<S: AsOsStr + ?Sized>(&mut self, arg: &S) -> &mut Command {
|
||||
pub fn arg<S: AsOsStr>(&mut self, arg: S) -> &mut Command {
|
||||
self.inner.arg(arg.as_os_str());
|
||||
self
|
||||
}
|
||||
|
@ -175,7 +175,7 @@ impl Command {
|
|||
/// Note that environment variable names are case-insensitive (but case-preserving) on Windows,
|
||||
/// and case-sensitive on all other platforms.
|
||||
#[stable(feature = "process", since = "1.0.0")]
|
||||
pub fn env<K: ?Sized, V: ?Sized>(&mut self, key: &K, val: &V) -> &mut Command
|
||||
pub fn env<K, V>(&mut self, key: K, val: V) -> &mut Command
|
||||
where K: AsOsStr, V: AsOsStr
|
||||
{
|
||||
self.inner.env(key.as_os_str(), val.as_os_str());
|
||||
|
@ -184,7 +184,7 @@ impl Command {
|
|||
|
||||
/// Removes an environment variable mapping.
|
||||
#[stable(feature = "process", since = "1.0.0")]
|
||||
pub fn env_remove<K: ?Sized + AsOsStr>(&mut self, key: &K) -> &mut Command {
|
||||
pub fn env_remove<K: AsOsStr>(&mut self, key: K) -> &mut Command {
|
||||
self.inner.env_remove(key.as_os_str());
|
||||
self
|
||||
}
|
||||
|
@ -198,7 +198,7 @@ impl Command {
|
|||
|
||||
/// Set the working directory for the child process.
|
||||
#[stable(feature = "process", since = "1.0.0")]
|
||||
pub fn current_dir<P: AsPath + ?Sized>(&mut self, dir: &P) -> &mut Command {
|
||||
pub fn current_dir<P: AsPath>(&mut self, dir: P) -> &mut Command {
|
||||
self.inner.cwd(dir.as_path().as_os_str());
|
||||
self
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue