Patchwork D8401: rust-chg: leverage impl trait at argument position

login
register
mail settings
Submitter phabricator
Date April 14, 2020, 4:42 p.m.
Message ID <535cf1cd39c7971c7469db58b94315a1@localhost.localdomain>
Download mbox | patch
Permalink /patch/46102/
State Not Applicable
Headers show

Comments

phabricator - April 14, 2020, 4:42 p.m.
Closed by commit rHG61fda2dbc522: rust-chg: leverage impl trait at argument position (authored by yuja).
This revision was automatically updated to reflect the committed changes.
This revision was not accepted when it landed; it landed in state "Needs Review".

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D8401?vs=21036&id=21072

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8401/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D8401

AFFECTED FILES
  rust/chg/src/clientext.rs
  rust/chg/src/locator.rs
  rust/chg/src/message.rs

CHANGE DETAILS




To: yuja, #hg-reviewers, Alphare
Cc: mercurial-devel

Patch

diff --git a/rust/chg/src/message.rs b/rust/chg/src/message.rs
--- a/rust/chg/src/message.rs
+++ b/rust/chg/src/message.rs
@@ -113,11 +113,9 @@ 
 ///
 /// Panics if key or value contains `\0` character, or key contains '='
 /// character.
-pub fn pack_env_vars_os<I, P>(vars: I) -> Bytes
-where
-    I: IntoIterator<Item = (P, P)>,
-    P: AsRef<OsStr>,
-{
+pub fn pack_env_vars_os(
+    vars: impl IntoIterator<Item = (impl AsRef<OsStr>, impl AsRef<OsStr>)>,
+) -> Bytes {
     let mut vars_iter = vars.into_iter();
     if let Some((k, v)) = vars_iter.next() {
         let mut dst = BytesMut::with_capacity(INITIAL_PACKED_ENV_VARS_CAPACITY);
@@ -143,17 +141,11 @@ 
     dst.put_slice(v.as_bytes());
 }
 
-fn decode_latin1<S>(s: S) -> String
-where
-    S: AsRef<[u8]>,
-{
+fn decode_latin1(s: impl AsRef<[u8]>) -> String {
     s.as_ref().iter().map(|&c| c as char).collect()
 }
 
-fn new_parse_error<E>(error: E) -> io::Error
-where
-    E: Into<Box<dyn error::Error + Send + Sync>>,
-{
+fn new_parse_error(error: impl Into<Box<dyn error::Error + Send + Sync>>) -> io::Error {
     io::Error::new(io::ErrorKind::InvalidData, error)
 }
 
diff --git a/rust/chg/src/locator.rs b/rust/chg/src/locator.rs
--- a/rust/chg/src/locator.rs
+++ b/rust/chg/src/locator.rs
@@ -75,11 +75,7 @@ 
     }
 
     /// Specifies the arguments to be passed to the server at start.
-    pub fn set_early_args<I, P>(&mut self, args: I)
-    where
-        I: IntoIterator<Item = P>,
-        P: AsRef<OsStr>,
-    {
+    pub fn set_early_args(&mut self, args: impl IntoIterator<Item = impl AsRef<OsStr>>) {
         self.hg_early_args = args.into_iter().map(|a| a.as_ref().to_owned()).collect();
     }
 
@@ -358,10 +354,7 @@ 
 /// Creates a directory which the other users cannot access to.
 ///
 /// If the directory already exists, tests its permission.
-fn create_secure_dir<P>(path: P) -> io::Result<()>
-where
-    P: AsRef<Path>,
-{
+fn create_secure_dir(path: impl AsRef<Path>) -> io::Result<()> {
     DirBuilder::new()
         .mode(0o700)
         .create(path.as_ref())
@@ -404,11 +397,7 @@ 
 }
 
 /// Collects arguments which need to be passed to the server at start.
-pub fn collect_early_args<I, P>(args: I) -> Vec<OsString>
-where
-    I: IntoIterator<Item = P>,
-    P: AsRef<OsStr>,
-{
+pub fn collect_early_args(args: impl IntoIterator<Item = impl AsRef<OsStr>>) -> Vec<OsString> {
     let mut args_iter = args.into_iter();
     let mut early_args = Vec::new();
     while let Some(arg) = args_iter.next() {
diff --git a/rust/chg/src/clientext.rs b/rust/chg/src/clientext.rs
--- a/rust/chg/src/clientext.rs
+++ b/rust/chg/src/clientext.rs
@@ -32,29 +32,27 @@ 
         E: AsRawFd;
 
     /// Changes the working directory of the server.
-    fn set_current_dir<P>(self, dir: P) -> OneShotRequest<C>
-    where
-        P: AsRef<Path>;
+    fn set_current_dir(self, dir: impl AsRef<Path>) -> OneShotRequest<C>;
 
     /// Updates the environment variables of the server.
-    fn set_env_vars_os<I, P>(self, vars: I) -> OneShotRequest<C>
-    where
-        I: IntoIterator<Item = (P, P)>,
-        P: AsRef<OsStr>;
+    fn set_env_vars_os(
+        self,
+        vars: impl IntoIterator<Item = (impl AsRef<OsStr>, impl AsRef<OsStr>)>,
+    ) -> OneShotRequest<C>;
 
     /// Changes the process title of the server.
-    fn set_process_name<P>(self, name: P) -> OneShotRequest<C>
-    where
-        P: AsRef<OsStr>;
+    fn set_process_name(self, name: impl AsRef<OsStr>) -> OneShotRequest<C>;
 
     /// Changes the umask of the server process.
     fn set_umask(self, mask: u32) -> OneShotRequest<C>;
 
     /// Runs the specified Mercurial command with cHg extension.
-    fn run_command_chg<I, P, H>(self, handler: H, args: I) -> ChgRunCommand<C, H>
+    fn run_command_chg<H>(
+        self,
+        handler: H,
+        args: impl IntoIterator<Item = impl AsRef<OsStr>>,
+    ) -> ChgRunCommand<C, H>
     where
-        I: IntoIterator<Item = P>,
-        P: AsRef<OsStr>,
         H: SystemHandler;
 
     /// Validates if the server can run Mercurial commands with the expected
@@ -65,10 +63,10 @@ 
     ///
     /// Client-side environment must be sent prior to this request, by
     /// `set_current_dir()` and `set_env_vars_os()`.
-    fn validate<I, P>(self, args: I) -> OneShotQuery<C, fn(Bytes) -> io::Result<Vec<Instruction>>>
-    where
-        I: IntoIterator<Item = P>,
-        P: AsRef<OsStr>;
+    fn validate(
+        self,
+        args: impl IntoIterator<Item = impl AsRef<OsStr>>,
+    ) -> OneShotQuery<C, fn(Bytes) -> io::Result<Vec<Instruction>>>;
 }
 
 impl<C> ChgClientExt<C> for Client<C>
@@ -84,25 +82,18 @@ 
         AttachIo::with_client(self, stdin, stdout, Some(stderr))
     }
 
-    fn set_current_dir<P>(self, dir: P) -> OneShotRequest<C>
-    where
-        P: AsRef<Path>,
-    {
+    fn set_current_dir(self, dir: impl AsRef<Path>) -> OneShotRequest<C> {
         OneShotRequest::start_with_args(self, b"chdir", dir.as_ref().as_os_str().as_bytes())
     }
 
-    fn set_env_vars_os<I, P>(self, vars: I) -> OneShotRequest<C>
-    where
-        I: IntoIterator<Item = (P, P)>,
-        P: AsRef<OsStr>,
-    {
+    fn set_env_vars_os(
+        self,
+        vars: impl IntoIterator<Item = (impl AsRef<OsStr>, impl AsRef<OsStr>)>,
+    ) -> OneShotRequest<C> {
         OneShotRequest::start_with_args(self, b"setenv", message::pack_env_vars_os(vars))
     }
 
-    fn set_process_name<P>(self, name: P) -> OneShotRequest<C>
-    where
-        P: AsRef<OsStr>,
-    {
+    fn set_process_name(self, name: impl AsRef<OsStr>) -> OneShotRequest<C> {
         OneShotRequest::start_with_args(self, b"setprocname", name.as_ref().as_bytes())
     }
 
@@ -112,20 +103,21 @@ 
         OneShotRequest::start_with_args(self, b"setumask2", args)
     }
 
-    fn run_command_chg<I, P, H>(self, handler: H, args: I) -> ChgRunCommand<C, H>
+    fn run_command_chg<H>(
+        self,
+        handler: H,
+        args: impl IntoIterator<Item = impl AsRef<OsStr>>,
+    ) -> ChgRunCommand<C, H>
     where
-        I: IntoIterator<Item = P>,
-        P: AsRef<OsStr>,
         H: SystemHandler,
     {
         ChgRunCommand::with_client(self, handler, message::pack_args_os(args))
     }
 
-    fn validate<I, P>(self, args: I) -> OneShotQuery<C, fn(Bytes) -> io::Result<Vec<Instruction>>>
-    where
-        I: IntoIterator<Item = P>,
-        P: AsRef<OsStr>,
-    {
+    fn validate(
+        self,
+        args: impl IntoIterator<Item = impl AsRef<OsStr>>,
+    ) -> OneShotQuery<C, fn(Bytes) -> io::Result<Vec<Instruction>>> {
         OneShotQuery::start_with_args(
             self,
             b"validate",