Skip to content

Commit cdc9242

Browse files
0.3.5-nightly traits From and Deref are const; fn as_array_of_cells
1 parent 427f81c commit cdc9242

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ndd"
3-
version = "0.2.5"
3+
version = "0.3.5-nightly"
44
edition = "2024"
55

66
license = "BSD-2-Clause OR Apache-2.0 OR MIT"

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)