diff options
| author | Marvin Löbel <loebel.marvin@gmail.com> | 2013-10-05 21:01:58 +0200 |
|---|---|---|
| committer | Marvin Löbel <loebel.marvin@gmail.com> | 2013-10-05 21:01:58 +0200 |
| commit | 49ac6baa726988c7a84dff3bdc8c1f8812940224 (patch) | |
| tree | 7d7494e4697685be1ddd541d411372d15e56050c /src/libstd/task | |
| parent | 1506dac10faf4b48f3d3debb9b20f2f55352deca (diff) | |
| download | rust-49ac6baa726988c7a84dff3bdc8c1f8812940224.tar.gz rust-49ac6baa726988c7a84dff3bdc8c1f8812940224.zip | |
Make a task name use a `SendStr`, allowing for either
static or owned strings
Diffstat (limited to 'src/libstd/task')
| -rw-r--r-- | src/libstd/task/mod.rs | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/libstd/task/mod.rs b/src/libstd/task/mod.rs index 74fcccc70e5..315b11cac08 100644 --- a/src/libstd/task/mod.rs +++ b/src/libstd/task/mod.rs @@ -63,6 +63,7 @@ use rt::in_green_task_context; use rt::local::Local; use unstable::finally::Finally; use util; +use send_str::{SendStr, IntoSendStr}; #[cfg(test)] use cast; #[cfg(test)] use comm::SharedChan; @@ -148,7 +149,7 @@ pub struct TaskOpts { watched: bool, indestructible: bool, notify_chan: Option<Chan<TaskResult>>, - name: Option<~str>, + name: Option<SendStr>, sched: SchedOpts, stack_size: Option<uint> } @@ -295,8 +296,8 @@ impl TaskBuilder { /// Name the task-to-be. Currently the name is used for identification /// only in failure messages. - pub fn name(&mut self, name: ~str) { - self.opts.name = Some(name); + pub fn name<S: IntoSendStr>(&mut self, name: S) { + self.opts.name = Some(name.into_send_str()); } /// Configure a custom scheduler mode for the task. @@ -944,7 +945,7 @@ fn test_unnamed_task() { } #[test] -fn test_named_task() { +fn test_owned_named_task() { use rt::test::run_in_newsched_task; do run_in_newsched_task { @@ -959,6 +960,21 @@ fn test_named_task() { } #[test] +fn test_static_named_task() { + use rt::test::run_in_newsched_task; + + do run_in_newsched_task { + let mut t = task(); + t.name("ada lovelace"); + do t.spawn { + do with_task_name |name| { + assert!(name.unwrap() == "ada lovelace"); + } + } + } +} + +#[test] fn test_run_basic() { let (po, ch) = stream::<()>(); let mut builder = task(); |
