diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-11-14 14:20:57 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-11-23 23:37:16 -0800 |
| commit | a9c1152c4bf72132806cb76045b3464d59db07da (patch) | |
| tree | 89ba92d5f5788e3323b75ca003bf74661a94e4de /src/libstd/lib.rs | |
| parent | 4e5259503cd8aac9905c7ac6d68d0c4caab1d28c (diff) | |
| download | rust-a9c1152c4bf72132806cb76045b3464d59db07da.tar.gz rust-a9c1152c4bf72132806cb76045b3464d59db07da.zip | |
std: Add a new top-level thread_local module
This commit removes the `std::local_data` module in favor of a new
`std::thread_local` module providing thread local storage. The module provides
two variants of TLS: one which owns its contents and one which is based on
scoped references. Each implementation has pros and cons listed in the
documentation.
Both flavors have accessors through a function called `with` which yield a
reference to a closure provided. Both flavors also panic if a reference cannot
be yielded and provide a function to test whether an access would panic or not.
This is an implementation of [RFC 461][rfc] and full details can be found in
that RFC.
This is a breaking change due to the removal of the `std::local_data` module.
All users can migrate to the new thread local system like so:
thread_local!(static FOO: Rc<RefCell<Option<T>>> = Rc::new(RefCell::new(None)))
The old `local_data` module inherently contained the `Rc<RefCell<Option<T>>>` as
an implementation detail which must now be explicitly stated by users.
[rfc]: https://github.com/rust-lang/rfcs/pull/461
[breaking-change]
Diffstat (limited to 'src/libstd/lib.rs')
| -rw-r--r-- | src/libstd/lib.rs | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index b35c49efdd8..77da727e94d 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -170,7 +170,6 @@ pub use core_collections::string; pub use core_collections::vec; pub use rustrt::c_str; -pub use rustrt::local_data; pub use unicode::char; @@ -209,17 +208,25 @@ pub mod prelude; #[path = "num/f32.rs"] pub mod f32; #[path = "num/f64.rs"] pub mod f64; -pub mod rand; - pub mod ascii; -pub mod time; - /* Common traits */ pub mod error; pub mod num; +/* Runtime and platform support */ + +pub mod thread_local; +pub mod c_vec; +pub mod dynamic_lib; +pub mod fmt; +pub mod io; +pub mod os; +pub mod path; +pub mod rand; +pub mod time; + /* Common data structures */ pub mod collections; @@ -230,15 +237,6 @@ pub mod hash; pub mod task; pub mod sync; -/* Runtime and platform support */ - -pub mod c_vec; -pub mod dynamic_lib; -pub mod os; -pub mod io; -pub mod path; -pub mod fmt; - #[cfg(unix)] #[path = "sys/unix/mod.rs"] mod sys; #[cfg(windows)] @@ -263,10 +261,12 @@ mod std { pub use error; // used for try!() pub use fmt; // used for any formatting strings pub use io; // used for println!() - pub use local_data; // used for local_data_key!() pub use option; // used for bitflags!{} pub use rt; // used for panic!() pub use vec; // used for vec![] + pub use cell; // used for tls! + pub use thread_local; // used for thread_local! + pub use kinds; // used for tls! // The test runner calls ::std::os::args() but really wants realstd #[cfg(test)] pub use realstd::os as os; @@ -276,4 +276,5 @@ mod std { pub use slice; pub use boxed; // used for vec![] + } |
