Skip to content

Commit c4f075b

Browse files
committed
1. Upgrading the library version to 0.1.8
2. A slight modification of the generator macro 3. Added additional comments 4. Adding the from_std function to all ManuallyDrop 5. Alteration of the into_inner and into_std_inner functions into ManuallyDrop 6. Transferring the Clone trait to the ManuallyDrop code generator 7. Minor fixes *_---
1 parent 594f2f8 commit c4f075b

File tree

6 files changed

+168
-95
lines changed

6 files changed

+168
-95
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "SafeManuallyDrop"
3-
version = "0.1.7"
3+
version = "0.1.8"
44
authors = ["Denis Kotlyarov (Денис Котляров) <[email protected]>"]
55
repository = "https://github.com/clucompany/SafeManuallyDrop.git"
66
edition = "2021"

examples/counter.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11

2-
32
// Let me remind you that CounterManuallyDrop by behavior allows undefined
43
// behavior in the same way as ManuallyDrop, but, unlike ManuallyDrop,
54
// Counter keeps a counter of the number of undefined behavior triggers.

src/beh/safe.rs

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,45 @@ pub struct SafeManuallyDrop<T, Trig> where T: ?Sized, Trig: TrigManuallyDrop {
1414

1515
crate::__codegen! {
1616
@use;
17-
#SafeManuallyDrop [
17+
@impl SafeManuallyDrop {
1818
is_safe: true,
1919
is_always_compatible: false,
2020
is_maybe_compatible: true,
2121
is_repr_transparent: false,
22-
];
23-
}
24-
25-
//impl<T> Copy for ManuallyDrop<T> where T: ?Sized + Copy {} TODO
26-
27-
impl<T, Trig> Clone for SafeManuallyDrop<T, Trig> where T: ?Sized + Clone, Trig: TrigManuallyDrop {
28-
#[inline(always)]
29-
fn clone(&self) -> Self {
30-
let ref_value: &T = self.deref();
31-
let state = self.state.clone();
3222

33-
Self {
34-
state,
35-
value: UnsafeStdManuallyDrop::new(Clone::clone(ref_value)),
36-
_pp: PhantomData,
23+
fn {
24+
/// Wrap a value to be manually dropped.
25+
new |value| {
26+
Self {
27+
value,
28+
state: StateManuallyDrop::empty(),
29+
_pp: PhantomData
30+
}
31+
}
32+
33+
as_unsafestd_manuallydrop |sself| {
34+
&sself.value
35+
}
36+
37+
as_mut_unsafestd_manuallydrop |sself| {
38+
&mut sself.value
39+
}
40+
41+
/// Get reference to value. Always unprotected!
42+
force_as_value |sself| {
43+
&sself.value
44+
}
45+
46+
/// Get a mutable reference to a value. Always unprotected!
47+
force_as_mut_value |sself| {
48+
&mut sself.value
49+
}
3750
}
3851
}
3952
}
4053

54+
//impl<T> Copy for ManuallyDrop<T> where T: ?Sized + Copy {} TODO
55+
4156
impl<T, Trig> Drop for SafeManuallyDrop<T, Trig> where T: ?Sized, Trig: TrigManuallyDrop {
4257
#[inline]
4358
fn drop(&mut self) {

src/beh/unsafe.rs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,40 @@ pub struct UnsafeManuallyDrop<T, Trig> where T: ?Sized, Trig: TrigManuallyDrop {
1212

1313
crate::__codegen! {
1414
@use;
15-
#UnsafeManuallyDrop [
15+
@impl UnsafeManuallyDrop {
1616
is_safe: false,
1717
is_always_compatible: true,
1818
is_maybe_compatible: true,
1919
is_repr_transparent: true,
20-
];
21-
}
22-
23-
impl<T, Trig> Copy for UnsafeManuallyDrop<T, Trig> where T: ?Sized + Copy, Trig: TrigManuallyDrop {}
24-
25-
impl<T, Trig> Clone for UnsafeManuallyDrop<T, Trig> where T: ?Sized + Clone, Trig: TrigManuallyDrop {
26-
#[inline(always)]
27-
fn clone(&self) -> Self {
28-
let ref_value = &self.value as &T;
29-
let value = Clone::clone(ref_value);
3020

31-
Self::new(value)
21+
fn {
22+
/// Wrap a value to be manually dropped.
23+
new |value| {
24+
Self {
25+
value,
26+
_pp: PhantomData
27+
}
28+
}
29+
30+
as_unsafestd_manuallydrop |sself| {
31+
&sself.value
32+
}
33+
34+
as_mut_unsafestd_manuallydrop |sself| {
35+
&mut sself.value
36+
}
37+
38+
/// Get reference to value. Always unprotected!
39+
force_as_value |sself| {
40+
&sself.value
41+
}
42+
43+
/// Get a mutable reference to a value. Always unprotected!
44+
force_as_mut_value |sself| {
45+
&mut sself.value
46+
}
47+
}
3248
}
3349
}
50+
51+
impl<T, Trig> Copy for UnsafeManuallyDrop<T, Trig> where T: ?Sized + Copy, Trig: TrigManuallyDrop {}

src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,15 @@ fn main() {
242242
// Anything related to deprecated features
243243
// will be removed in a future regression release.
244244
//
245+
// 0.1.0
246+
// 0.1.2
247+
// ... unk
248+
// 0.1.5
249+
// 0.1.6
250+
// 0.1.7
251+
// 0.1.8 <-- current
252+
// 1.0.0 <--
253+
//
245254

246255
#![allow(non_snake_case)]
247256

0 commit comments

Comments
 (0)