diff options
| author | Marvin Löbel <loebel.marvin@gmail.com> | 2013-09-14 19:37:45 +0200 |
|---|---|---|
| committer | Marvin Löbel <loebel.marvin@gmail.com> | 2013-09-16 16:57:50 +0200 |
| commit | 76c3e8a38cea2fe6342d83158c267e57a6b1f53f (patch) | |
| tree | db7c6ca84a3e769ed40343411ecf43f369883418 /src/libstd/rt | |
| parent | 3e1803f3af1adc1b2e5595650f6920f40bbedc2e (diff) | |
| download | rust-76c3e8a38cea2fe6342d83158c267e57a6b1f53f.tar.gz rust-76c3e8a38cea2fe6342d83158c267e57a6b1f53f.zip | |
Add an SendStr type
A SendStr is a string that can hold either a ~str or a &'static str. This can be useful as an optimization when an allocation is sometimes needed but the common case is statically known. Possible use cases include Maps with both static and owned keys, or propagating error messages across task boundaries. SendStr implements most basic traits in a way that hides the fact that it is an enum; in particular things like order and equality are only determined by the content of the wrapped strings. Replaced std::rt:logging::SendableString with SendStr Added tests for using an SendStr as key in Hash- and Treemaps
Diffstat (limited to 'src/libstd/rt')
| -rw-r--r-- | src/libstd/rt/logging.rs | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/src/libstd/rt/logging.rs b/src/libstd/rt/logging.rs index 54084bb14c0..fbe05267cf4 100644 --- a/src/libstd/rt/logging.rs +++ b/src/libstd/rt/logging.rs @@ -17,6 +17,7 @@ use str::raw::from_c_str; use u32; use vec::ImmutableVector; use cast::transmute; +use send_str::{SendStr, SendStrOwned, SendStrStatic}; struct LogDirective { name: Option<~str>, @@ -168,20 +169,14 @@ fn update_log_settings(crate_map: *u8, settings: ~str) { } } -/// Represent a string with `Send` bound. -pub enum SendableString { - OwnedString(~str), - StaticString(&'static str) -} - pub trait Logger { - fn log(&mut self, msg: SendableString); + fn log(&mut self, msg: SendStr); } pub struct StdErrLogger; impl Logger for StdErrLogger { - fn log(&mut self, msg: SendableString) { + fn log(&mut self, msg: SendStr) { use io::{Writer, WriterUtil}; if !should_log_console() { @@ -189,11 +184,11 @@ impl Logger for StdErrLogger { } let s: &str = match msg { - OwnedString(ref s) => { + SendStrOwned(ref s) => { let slc: &str = *s; slc }, - StaticString(s) => s, + SendStrStatic(s) => s, }; // Truncate the string |
