diff options
| author | bors <bors@rust-lang.org> | 2013-12-26 18:32:15 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-12-26 18:32:15 -0800 |
| commit | 00d87e0d8198ffb268251b5af2eb2ce19249c7f8 (patch) | |
| tree | cee6dd55e5bef0dfae18766a3a15a61095aab672 /src/libstd | |
| parent | f74b8f0d3a90fd3b64afa38b9470d9a45cd04ee9 (diff) | |
| parent | ad160146fdf55a3efb8dcdf7d428ae09a20eca01 (diff) | |
| download | rust-00d87e0d8198ffb268251b5af2eb2ce19249c7f8.tar.gz rust-00d87e0d8198ffb268251b5af2eb2ce19249c7f8.zip | |
auto merge of #11058 : pcwalton/rust/demuting, r=pcwalton
r? @alexcrichton
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/cell.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/libstd/cell.rs b/src/libstd/cell.rs index 62fc08fd9d3..c5fdddfec76 100644 --- a/src/libstd/cell.rs +++ b/src/libstd/cell.rs @@ -21,6 +21,33 @@ pub struct Cell<T> { priv value: T, } +#[cfg(stage0)] +impl<T> Cell<T> { + /// Creates a new `Cell` containing the given value. + pub fn new(value: T) -> Cell<T> { + Cell { + value: value, + } + } + + /// Returns a copy of the contained value. + #[inline] + pub fn get(&self) -> T { + unsafe { + ::cast::transmute_copy(&self.value) + } + } + + /// Sets the contained value. + #[inline] + pub fn set(&self, value: T) { + unsafe { + *cast::transmute_mut(&self.value) = value + } + } +} + +#[cfg(not(stage0))] impl<T: ::kinds::Pod> Cell<T> { /// Creates a new `Cell` containing the given value. pub fn new(value: T) -> Cell<T> { |
