diff options
| author | Aaron Turon <aturon@mozilla.com> | 2014-07-02 13:50:45 -0700 |
|---|---|---|
| committer | Aaron Turon <aturon@mozilla.com> | 2014-07-10 12:16:16 -0700 |
| commit | bfa853f8ed45d1908c98ec350f52c7a6790661da (patch) | |
| tree | 96c101298ae0503bd64bb51201e2154eeb88d905 /src/librustrt | |
| parent | f9fe251777e9f1cc557a6d5b82b45403935d0a10 (diff) | |
| download | rust-bfa853f8ed45d1908c98ec350f52c7a6790661da.tar.gz rust-bfa853f8ed45d1908c98ec350f52c7a6790661da.zip | |
io::process::Command: add fine-grained env builder
This commit changes the `io::process::Command` API to provide fine-grained control over the environment: * The `env` method now inserts/updates a key/value pair. * The `env_remove` method removes a key from the environment. * The old `env` method, which sets the entire environment in one shot, is renamed to `env_set_all`. It can be used in conjunction with the finer-grained methods. This renaming is a breaking change. To support these new methods, the internal `env` representation for `Command` has been changed to an optional `HashMap` holding owned `CString`s (to support non-utf8 data). The `HashMap` is only materialized if the environment is updated. The implementation does not try hard to avoid allocation, since the cost of launching a process will dwarf any allocation cost. This patch also adds `PartialOrd`, `Eq`, and `Hash` implementations for `CString`. [breaking-change]
Diffstat (limited to 'src/librustrt')
| -rw-r--r-- | src/librustrt/c_str.rs | 17 | ||||
| -rw-r--r-- | src/librustrt/lib.rs | 2 | ||||
| -rw-r--r-- | src/librustrt/rtio.rs | 2 |
3 files changed, 19 insertions, 2 deletions
diff --git a/src/librustrt/c_str.rs b/src/librustrt/c_str.rs index 06f4e71871d..396d51f4fcb 100644 --- a/src/librustrt/c_str.rs +++ b/src/librustrt/c_str.rs @@ -69,6 +69,7 @@ use core::prelude::*; use alloc::libc_heap::malloc_raw; use collections::string::String; +use collections::hash; use core::kinds::marker; use core::mem; use core::ptr; @@ -116,6 +117,22 @@ impl PartialEq for CString { } } +impl PartialOrd for CString { + #[inline] + fn partial_cmp(&self, other: &CString) -> Option<Ordering> { + self.as_bytes().partial_cmp(&other.as_bytes()) + } +} + +impl Eq for CString {} + +impl<S: hash::Writer> hash::Hash<S> for CString { + #[inline] + fn hash(&self, state: &mut S) { + self.as_bytes().hash(state) + } +} + impl CString { /// Create a C String from a pointer. pub unsafe fn new(buf: *const libc::c_char, owns_buffer: bool) -> CString { diff --git a/src/librustrt/lib.rs b/src/librustrt/lib.rs index b707c62bb70..c830b2e122e 100644 --- a/src/librustrt/lib.rs +++ b/src/librustrt/lib.rs @@ -17,7 +17,7 @@ html_root_url = "http://doc.rust-lang.org/0.11.0/")] #![feature(macro_rules, phase, globs, thread_local, managed_boxes, asm)] -#![feature(linkage, lang_items, unsafe_destructor)] +#![feature(linkage, lang_items, unsafe_destructor, default_type_params)] #![no_std] #![experimental] diff --git a/src/librustrt/rtio.rs b/src/librustrt/rtio.rs index 0205f2405f9..7a91cca6265 100644 --- a/src/librustrt/rtio.rs +++ b/src/librustrt/rtio.rs @@ -75,7 +75,7 @@ pub struct ProcessConfig<'a> { /// Optional environment to specify for the program. If this is None, then /// it will inherit the current process's environment. - pub env: Option<&'a [(CString, CString)]>, + pub env: Option<&'a [(&'a CString, &'a CString)]>, /// Optional working directory for the new process. If this is None, then /// the current directory of the running process is inherited. |
