summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCyril Plisko <cyril.plisko@mountall.com>2017-05-03 23:29:16 +0300
committerCyril Plisko <cyril.plisko@mountall.com>2017-05-04 08:22:18 +0300
commit7d5d43ca9c489d6a40b896339bced64fbc378cfc (patch)
treebd4a3e651483dbd724d134559ca47a9d2e54fdd8
parente3948ce267f243f6787d2a4fce6d12b042544fa3 (diff)
Consume strings rather than clone() the references
-rw-r--r--src/utils.rs9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/utils.rs b/src/utils.rs
index 43458ce..78c4d8a 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -6,8 +6,8 @@ use std::ptr;
use errno;
use libc;
-fn osstring2cstring(s: &OsString) -> CString {
- unsafe { CString::from_vec_unchecked(s.clone().into_vec()) }
+fn osstring2cstring(s: OsString) -> CString {
+ unsafe { CString::from_vec_unchecked(s.into_vec()) }
}
fn split_string(s: &OsString) -> Vec<OsString> {
@@ -23,7 +23,10 @@ pub fn fork() -> libc::pid_t {
}
pub fn execvp(cmd: &OsString) {
- let cstrings = split_string(cmd).iter().map(osstring2cstring).collect::<Vec<_>>();
+ let cstrings = split_string(cmd)
+ .into_iter()
+ .map(osstring2cstring)
+ .collect::<Vec<_>>();
let mut args = cstrings.iter().map(|c| c.as_ptr()).collect::<Vec<_>>();
args.push(ptr::null());
errno::set_errno(errno::Errno(0));