##// END OF EJS Templates
rust-chg: leverage impl trait at argument position...
Yuya Nishihara -
r45183:61fda2db default
parent child Browse files
Show More
@@ -32,29 +32,27 b' where'
32 32 E: AsRawFd;
33 33
34 34 /// Changes the working directory of the server.
35 fn set_current_dir<P>(self, dir: P) -> OneShotRequest<C>
36 where
37 P: AsRef<Path>;
35 fn set_current_dir(self, dir: impl AsRef<Path>) -> OneShotRequest<C>;
38 36
39 37 /// Updates the environment variables of the server.
40 fn set_env_vars_os<I, P>(self, vars: I) -> OneShotRequest<C>
41 where
42 I: IntoIterator<Item = (P, P)>,
43 P: AsRef<OsStr>;
38 fn set_env_vars_os(
39 self,
40 vars: impl IntoIterator<Item = (impl AsRef<OsStr>, impl AsRef<OsStr>)>,
41 ) -> OneShotRequest<C>;
44 42
45 43 /// Changes the process title of the server.
46 fn set_process_name<P>(self, name: P) -> OneShotRequest<C>
47 where
48 P: AsRef<OsStr>;
44 fn set_process_name(self, name: impl AsRef<OsStr>) -> OneShotRequest<C>;
49 45
50 46 /// Changes the umask of the server process.
51 47 fn set_umask(self, mask: u32) -> OneShotRequest<C>;
52 48
53 49 /// Runs the specified Mercurial command with cHg extension.
54 fn run_command_chg<I, P, H>(self, handler: H, args: I) -> ChgRunCommand<C, H>
50 fn run_command_chg<H>(
51 self,
52 handler: H,
53 args: impl IntoIterator<Item = impl AsRef<OsStr>>,
54 ) -> ChgRunCommand<C, H>
55 55 where
56 I: IntoIterator<Item = P>,
57 P: AsRef<OsStr>,
58 56 H: SystemHandler;
59 57
60 58 /// Validates if the server can run Mercurial commands with the expected
@@ -65,10 +63,10 b' where'
65 63 ///
66 64 /// Client-side environment must be sent prior to this request, by
67 65 /// `set_current_dir()` and `set_env_vars_os()`.
68 fn validate<I, P>(self, args: I) -> OneShotQuery<C, fn(Bytes) -> io::Result<Vec<Instruction>>>
69 where
70 I: IntoIterator<Item = P>,
71 P: AsRef<OsStr>;
66 fn validate(
67 self,
68 args: impl IntoIterator<Item = impl AsRef<OsStr>>,
69 ) -> OneShotQuery<C, fn(Bytes) -> io::Result<Vec<Instruction>>>;
72 70 }
73 71
74 72 impl<C> ChgClientExt<C> for Client<C>
@@ -84,25 +82,18 b' where'
84 82 AttachIo::with_client(self, stdin, stdout, Some(stderr))
85 83 }
86 84
87 fn set_current_dir<P>(self, dir: P) -> OneShotRequest<C>
88 where
89 P: AsRef<Path>,
90 {
85 fn set_current_dir(self, dir: impl AsRef<Path>) -> OneShotRequest<C> {
91 86 OneShotRequest::start_with_args(self, b"chdir", dir.as_ref().as_os_str().as_bytes())
92 87 }
93 88
94 fn set_env_vars_os<I, P>(self, vars: I) -> OneShotRequest<C>
95 where
96 I: IntoIterator<Item = (P, P)>,
97 P: AsRef<OsStr>,
98 {
89 fn set_env_vars_os(
90 self,
91 vars: impl IntoIterator<Item = (impl AsRef<OsStr>, impl AsRef<OsStr>)>,
92 ) -> OneShotRequest<C> {
99 93 OneShotRequest::start_with_args(self, b"setenv", message::pack_env_vars_os(vars))
100 94 }
101 95
102 fn set_process_name<P>(self, name: P) -> OneShotRequest<C>
103 where
104 P: AsRef<OsStr>,
105 {
96 fn set_process_name(self, name: impl AsRef<OsStr>) -> OneShotRequest<C> {
106 97 OneShotRequest::start_with_args(self, b"setprocname", name.as_ref().as_bytes())
107 98 }
108 99
@@ -112,20 +103,21 b' where'
112 103 OneShotRequest::start_with_args(self, b"setumask2", args)
113 104 }
114 105
115 fn run_command_chg<I, P, H>(self, handler: H, args: I) -> ChgRunCommand<C, H>
106 fn run_command_chg<H>(
107 self,
108 handler: H,
109 args: impl IntoIterator<Item = impl AsRef<OsStr>>,
110 ) -> ChgRunCommand<C, H>
116 111 where
117 I: IntoIterator<Item = P>,
118 P: AsRef<OsStr>,
119 112 H: SystemHandler,
120 113 {
121 114 ChgRunCommand::with_client(self, handler, message::pack_args_os(args))
122 115 }
123 116
124 fn validate<I, P>(self, args: I) -> OneShotQuery<C, fn(Bytes) -> io::Result<Vec<Instruction>>>
125 where
126 I: IntoIterator<Item = P>,
127 P: AsRef<OsStr>,
128 {
117 fn validate(
118 self,
119 args: impl IntoIterator<Item = impl AsRef<OsStr>>,
120 ) -> OneShotQuery<C, fn(Bytes) -> io::Result<Vec<Instruction>>> {
129 121 OneShotQuery::start_with_args(
130 122 self,
131 123 b"validate",
@@ -75,11 +75,7 b' impl Locator {'
75 75 }
76 76
77 77 /// Specifies the arguments to be passed to the server at start.
78 pub fn set_early_args<I, P>(&mut self, args: I)
79 where
80 I: IntoIterator<Item = P>,
81 P: AsRef<OsStr>,
82 {
78 pub fn set_early_args(&mut self, args: impl IntoIterator<Item = impl AsRef<OsStr>>) {
83 79 self.hg_early_args = args.into_iter().map(|a| a.as_ref().to_owned()).collect();
84 80 }
85 81
@@ -358,10 +354,7 b' fn default_timeout() -> Duration {'
358 354 /// Creates a directory which the other users cannot access to.
359 355 ///
360 356 /// If the directory already exists, tests its permission.
361 fn create_secure_dir<P>(path: P) -> io::Result<()>
362 where
363 P: AsRef<Path>,
364 {
357 fn create_secure_dir(path: impl AsRef<Path>) -> io::Result<()> {
365 358 DirBuilder::new()
366 359 .mode(0o700)
367 360 .create(path.as_ref())
@@ -404,11 +397,7 b' fn check_server_capabilities(spec: &Serv'
404 397 }
405 398
406 399 /// Collects arguments which need to be passed to the server at start.
407 pub fn collect_early_args<I, P>(args: I) -> Vec<OsString>
408 where
409 I: IntoIterator<Item = P>,
410 P: AsRef<OsStr>,
411 {
400 pub fn collect_early_args(args: impl IntoIterator<Item = impl AsRef<OsStr>>) -> Vec<OsString> {
412 401 let mut args_iter = args.into_iter();
413 402 let mut early_args = Vec::new();
414 403 while let Some(arg) = args_iter.next() {
@@ -113,11 +113,9 b' const INITIAL_PACKED_ENV_VARS_CAPACITY: '
113 113 ///
114 114 /// Panics if key or value contains `\0` character, or key contains '='
115 115 /// character.
116 pub fn pack_env_vars_os<I, P>(vars: I) -> Bytes
117 where
118 I: IntoIterator<Item = (P, P)>,
119 P: AsRef<OsStr>,
120 {
116 pub fn pack_env_vars_os(
117 vars: impl IntoIterator<Item = (impl AsRef<OsStr>, impl AsRef<OsStr>)>,
118 ) -> Bytes {
121 119 let mut vars_iter = vars.into_iter();
122 120 if let Some((k, v)) = vars_iter.next() {
123 121 let mut dst = BytesMut::with_capacity(INITIAL_PACKED_ENV_VARS_CAPACITY);
@@ -143,17 +141,11 b' fn pack_env_into(dst: &mut BytesMut, k: '
143 141 dst.put_slice(v.as_bytes());
144 142 }
145 143
146 fn decode_latin1<S>(s: S) -> String
147 where
148 S: AsRef<[u8]>,
149 {
144 fn decode_latin1(s: impl AsRef<[u8]>) -> String {
150 145 s.as_ref().iter().map(|&c| c as char).collect()
151 146 }
152 147
153 fn new_parse_error<E>(error: E) -> io::Error
154 where
155 E: Into<Box<dyn error::Error + Send + Sync>>,
156 {
148 fn new_parse_error(error: impl Into<Box<dyn error::Error + Send + Sync>>) -> io::Error {
157 149 io::Error::new(io::ErrorKind::InvalidData, error)
158 150 }
159 151
General Comments 0
You need to be logged in to leave comments. Login now