diff options
| author | Philipp Oppermann <dev@phil-opp.com> | 2015-10-13 17:11:49 +0200 |
|---|---|---|
| committer | Philipp Oppermann <dev@phil-opp.com> | 2015-10-20 19:56:45 +0200 |
| commit | 3ed79944e8b5fc69f325db955336aff86e9210e5 (patch) | |
| tree | 6b0cf20dff7ec08daac9ce86434329be89028974 | |
| parent | a9d528534477281bab5cdd5b95e9c667f25ac21e (diff) | |
Make Unique::new const function
| -rw-r--r-- | src/libcore/ptr.rs | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 8adbaf56f14..63057aadf77 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -498,12 +498,28 @@ unsafe impl<T: Send + ?Sized> Send for Unique<T> { } #[unstable(feature = "unique", issue = "27730")] unsafe impl<T: Sync + ?Sized> Sync for Unique<T> { } +#[cfg(stage0)] +macro_rules! unique_new { + () => ( + /// Creates a new `Unique`. + pub unsafe fn new(ptr: *mut T) -> Unique<T> { + Unique { pointer: NonZero::new(ptr), _marker: PhantomData } + } + ) +} +#[cfg(not(stage0))] +macro_rules! unique_new { + () => ( + /// Creates a new `Unique`. + pub unsafe const fn new(ptr: *mut T) -> Unique<T> { + Unique { pointer: NonZero::new(ptr), _marker: PhantomData } + } + ) +} + #[unstable(feature = "unique", issue = "27730")] impl<T: ?Sized> Unique<T> { - /// Creates a new `Unique`. - pub unsafe fn new(ptr: *mut T) -> Unique<T> { - Unique { pointer: NonZero::new(ptr), _marker: PhantomData } - } + unique_new!{} /// Dereferences the content. pub unsafe fn get(&self) -> &T { |
