Skip to content

Commit

Permalink
cargo clippy & fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-marinica committed Nov 18, 2024
1 parent cc250e1 commit 835d656
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 26 deletions.
7 changes: 2 additions & 5 deletions framework/base/src/types/managed/basic/big_float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,9 @@ impl<M: ManagedTypeApi> ManagedType<M> for BigFloat<M> {
self.handle.clone()
}

unsafe fn forget_into_handle(mut self) -> Self::OwnHandle {
unsafe fn forget_into_handle(self) -> Self::OwnHandle {
unsafe {
let handle = core::mem::replace(
&mut self.handle,
core::mem::MaybeUninit::uninit().assume_init(),
);
let handle = core::ptr::read(&self.handle);
core::mem::forget(self);
handle
}
Expand Down
7 changes: 2 additions & 5 deletions framework/base/src/types/managed/basic/big_int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,9 @@ impl<M: ManagedTypeApi> ManagedType<M> for BigInt<M> {
self.handle.clone()
}

unsafe fn forget_into_handle(mut self) -> Self::OwnHandle {
unsafe fn forget_into_handle(self) -> Self::OwnHandle {
unsafe {
let handle = core::mem::replace(
&mut self.handle,
core::mem::MaybeUninit::uninit().assume_init(),
);
let handle = core::ptr::read(&self.handle);
core::mem::forget(self);
handle
}
Expand Down
7 changes: 2 additions & 5 deletions framework/base/src/types/managed/basic/elliptic_curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,9 @@ impl<M: ManagedTypeApi> ManagedType<M> for EllipticCurve<M> {
self.handle.clone()
}

unsafe fn forget_into_handle(mut self) -> Self::OwnHandle {
unsafe fn forget_into_handle(self) -> Self::OwnHandle {
unsafe {
let handle = core::mem::replace(
&mut self.handle,
core::mem::MaybeUninit::uninit().assume_init(),
);
let handle = core::ptr::read(&self.handle);
core::mem::forget(self);
handle
}
Expand Down
7 changes: 2 additions & 5 deletions framework/base/src/types/managed/basic/managed_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,9 @@ impl<M: ManagedTypeApi> ManagedType<M> for ManagedBuffer<M> {
self.handle.clone()
}

unsafe fn forget_into_handle(mut self) -> Self::OwnHandle {
unsafe fn forget_into_handle(self) -> Self::OwnHandle {
unsafe {
let handle = core::mem::replace(
&mut self.handle,
core::mem::MaybeUninit::uninit().assume_init(),
);
let handle = core::ptr::read(&self.handle);
core::mem::forget(self);
handle
}
Expand Down
7 changes: 2 additions & 5 deletions framework/base/src/types/managed/basic/managed_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@ impl<M: ManagedTypeApi> ManagedType<M> for ManagedMap<M> {
self.handle.clone()
}

unsafe fn forget_into_handle(mut self) -> Self::OwnHandle {
unsafe fn forget_into_handle(self) -> Self::OwnHandle {
unsafe {
let handle = core::mem::replace(
&mut self.handle,
core::mem::MaybeUninit::uninit().assume_init(),
);
let handle = core::ptr::read(&self.handle);
core::mem::forget(self);
handle
}
Expand Down
12 changes: 11 additions & 1 deletion framework/base/src/types/managed/managed_type_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,18 @@ pub trait ManagedType<M: ManagedTypeApi>: Sized {
fn get_handle(&self) -> Self::OwnHandle;

/// Forgets current object (does not run destructor), but extracts the handle.
///
///
/// The handle remains an owned object, so the handle's destructor will run later, when dropped.
///
/// ## Safety
///
/// Destructures the object, without running a constructor.
///
/// To avoid a memory leak, it is necessary for the object to be later
/// reconstructed from handle and its destructor run.
///
/// It is designed to be used ManagedVec and ManagedOption,
/// where items are dropped later, together with their container.
unsafe fn forget_into_handle(self) -> Self::OwnHandle;

#[doc(hidden)]
Expand Down

0 comments on commit 835d656

Please sign in to comment.