Skip to content

Commit 2a478c7

Browse files
bors[bot]CAD97
andauthored
Merge #55
55: impl [Try]AllocSliceDst for [A]RcBox r=CAD97 a=CAD97 Co-authored-by: CAD97 <cad97@cad97.com>
2 parents 2afe341 + 966c977 commit 2a478c7

File tree

3 files changed

+51
-6
lines changed

3 files changed

+51
-6
lines changed

Cargo.lock

Lines changed: 26 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/rc-box/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rc-box"
3-
version = "1.0.0"
3+
version = "1.1.0"
44
edition = "2018"
55

66
authors = ["Christopher Durham (cad97) <cad97@cad97.com>"]
@@ -17,6 +17,9 @@ maintenance = { status = "passively-maintained" }
1717
[features]
1818
default = ["erasable"]
1919

20+
[dependencies]
21+
slice-dst = { version = "1.4.0", optional = true }
22+
2023
[dependencies.erasable]
2124
version = "1.0.0"
2225
path = "../erasable"

crates/rc-box/src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ extern crate std;
1818

1919
#[cfg(feature = "erasable")]
2020
use erasable::{Erasable, ErasablePtr, ErasedPtr};
21+
#[cfg(feature = "slice-dst")]
22+
use slice_dst::{AllocSliceDst, SliceDst, TryAllocSliceDst};
2123
#[cfg(feature = "std")]
2224
use std::panic::UnwindSafe;
2325
use {
@@ -352,6 +354,25 @@ then the data will be pinned in memory and unable to be moved."),
352354
}
353355
}
354356

357+
#[cfg(feature = "slice-dst")]
358+
unsafe impl<S: ?Sized + SliceDst> AllocSliceDst<S> for $RcBox<S> {
359+
unsafe fn new_slice_dst<I>(len: usize, init: I) -> Self
360+
where
361+
I: FnOnce(ptr::NonNull<S>),
362+
{
363+
Self::from_unchecked($Rc::new_slice_dst(len, init))
364+
}
365+
}
366+
#[cfg(feature = "slice-dst")]
367+
unsafe impl<S: ?Sized + SliceDst> TryAllocSliceDst<S> for $RcBox<S> {
368+
unsafe fn try_new_slice_dst<I, E>(len: usize, init: I) -> Result<Self, E>
369+
where
370+
I: FnOnce(ptr::NonNull<S>) -> Result<(), E>,
371+
{
372+
$Rc::try_new_slice_dst(len, init).map(|x| Self::from_unchecked(x))
373+
}
374+
}
375+
355376
impl<T: ?Sized> AsMut<T> for $RcBox<T> {
356377
fn as_mut(&mut self) -> &mut T {
357378
&mut **self

0 commit comments

Comments
 (0)