Skip to content

Commit a63c332

Browse files
NIGHTLY: const Deref and From; as_array_of_cells
1 parent cfeb442 commit a63c332

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

rust-toolchain.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[toolchain]
2+
channel = "nightly"

src/lib.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![doc = include_str!("../README.md")]
22
#![cfg_attr(not(any(doc, test)), no_std)]
3+
#![feature(const_convert, const_trait_impl)]
34

45
use core::any::Any;
56
use core::cell::Cell;
@@ -58,20 +59,26 @@ impl<T: Any> NonDeDuplicated<T> {
5859
}
5960
}
6061

61-
impl<T: Any> Deref for NonDeDuplicated<T> {
62+
impl<T: Any> const Deref for NonDeDuplicated<T> {
6263
type Target = T;
6364

6465
fn deref(&self) -> &Self::Target {
6566
self.get()
6667
}
6768
}
6869

69-
impl<T: Any> From<T> for NonDeDuplicated<T> {
70+
impl<T: Any> const From<T> for NonDeDuplicated<T> {
7071
fn from(value: T) -> Self {
7172
Self::new(value)
7273
}
7374
}
7475

76+
impl<T: Any, const N: usize> NonDeDuplicated<[T; N]> {
77+
pub const fn as_array_of_cells(&self) -> &[NonDeDuplicated<T>; N] {
78+
unsafe { core::mem::transmute(self.cell.as_array_of_cells()) }
79+
}
80+
}
81+
7582
/// For now, [Sync] requires that `T` is both [Sync] AND [Send], following
7683
/// [std::sync::Mutex](https://doc.rust-lang.org/nightly/std/sync/struct.Mutex.html#impl-Sync-for-Mutex%3CT%3E).
7784
/// However, from <https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html> it seems that `T:

0 commit comments

Comments
 (0)