#[repr(transparent)]pub struct NoCopy<T: ?Sized>(pub T);Expand description
A simple packer, but no implement copy
This crate originates from the behavior of non move closures when capturing Copy types
§Examples
ⓘ
let value;
{
let n = 2;
value = || n+1;
}
assert_eq!(value(), 3);Imagine that it will compile? Actually, it won’t
For non move closures, if owned uses a copy types value, it will actually capture the reference
Use NoCopy to make n no longer a copy types, compile passed:
let value;
{
let n = no_copy::NoCopy(2);
value = || n+1;
}
assert_eq!(value(), 3);Tuple Fields§
§0: TAvoid use x.0 inside the closure, as the closure can capture fields
Trying *{x} or {x}.0?
Implementations§
Trait Implementations§
Source§impl<T: AddAssign<U>, U> AddAssign<U> for NoCopy<T>
impl<T: AddAssign<U>, U> AddAssign<U> for NoCopy<T>
Source§fn add_assign(&mut self, rhs: U)
fn add_assign(&mut self, rhs: U)
Performs the
+= operation. Read moreSource§impl<T: BitAndAssign<U>, U> BitAndAssign<U> for NoCopy<T>
impl<T: BitAndAssign<U>, U> BitAndAssign<U> for NoCopy<T>
Source§fn bitand_assign(&mut self, rhs: U)
fn bitand_assign(&mut self, rhs: U)
Performs the
&= operation. Read moreSource§impl<T: BitOrAssign<U>, U> BitOrAssign<U> for NoCopy<T>
impl<T: BitOrAssign<U>, U> BitOrAssign<U> for NoCopy<T>
Source§fn bitor_assign(&mut self, rhs: U)
fn bitor_assign(&mut self, rhs: U)
Performs the
|= operation. Read moreSource§impl<T: BitXorAssign<U>, U> BitXorAssign<U> for NoCopy<T>
impl<T: BitXorAssign<U>, U> BitXorAssign<U> for NoCopy<T>
Source§fn bitxor_assign(&mut self, rhs: U)
fn bitxor_assign(&mut self, rhs: U)
Performs the
^= operation. Read moreSource§impl<T: ?Sized> BorrowMut<T> for NoCopy<T>
impl<T: ?Sized> BorrowMut<T> for NoCopy<T>
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<H: BuildHasher> BuildHasher for NoCopy<H>
impl<H: BuildHasher> BuildHasher for NoCopy<H>
Source§impl<T: DivAssign<U>, U> DivAssign<U> for NoCopy<T>
impl<T: DivAssign<U>, U> DivAssign<U> for NoCopy<T>
Source§fn div_assign(&mut self, rhs: U)
fn div_assign(&mut self, rhs: U)
Performs the
/= operation. Read moreimpl<T: Eq + ?Sized> Eq for NoCopy<T>
Source§impl<T: Extend<A>, A> Extend<A> for NoCopy<T>
impl<T: Extend<A>, A> Extend<A> for NoCopy<T>
Source§fn extend<T1: IntoIterator<Item = A>>(&mut self, iter: T1)
fn extend<T1: IntoIterator<Item = A>>(&mut self, iter: T1)
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one)Reserves capacity in a collection for the given number of additional elements. Read more
Source§impl<H: ?Sized + Hasher> Hasher for NoCopy<H>
impl<H: ?Sized + Hasher> Hasher for NoCopy<H>
Source§fn write_u128(&mut self, i: u128)
fn write_u128(&mut self, i: u128)
Writes a single
u128 into this hasher.Source§fn write_usize(&mut self, i: usize)
fn write_usize(&mut self, i: usize)
Writes a single
usize into this hasher.Source§fn write_i128(&mut self, i: i128)
fn write_i128(&mut self, i: i128)
Writes a single
i128 into this hasher.Source§fn write_isize(&mut self, i: isize)
fn write_isize(&mut self, i: isize)
Writes a single
isize into this hasher.Source§fn write_length_prefix(&mut self, len: usize)
fn write_length_prefix(&mut self, len: usize)
🔬This is a nightly-only experimental API. (
hasher_prefixfree_extras)Writes a length prefix into this hasher, as part of being prefix-free. Read more
Source§impl<T: IntoIterator> IntoIterator for NoCopy<T>
impl<T: IntoIterator> IntoIterator for NoCopy<T>
Source§impl<T: MulAssign<U>, U> MulAssign<U> for NoCopy<T>
impl<T: MulAssign<U>, U> MulAssign<U> for NoCopy<T>
Source§fn mul_assign(&mut self, rhs: U)
fn mul_assign(&mut self, rhs: U)
Performs the
*= operation. Read moreSource§impl<T: Ord + ?Sized> Ord for NoCopy<T>
impl<T: Ord + ?Sized> Ord for NoCopy<T>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<T: PartialOrd + ?Sized> PartialOrd for NoCopy<T>
impl<T: PartialOrd + ?Sized> PartialOrd for NoCopy<T>
Source§impl<T: ?Sized + PartialOrd> PartialOrd<T> for NoCopy<T>
impl<T: ?Sized + PartialOrd> PartialOrd<T> for NoCopy<T>
Source§impl<T: RangeBounds<R>, R> RangeBounds<R> for NoCopy<T>
impl<T: RangeBounds<R>, R> RangeBounds<R> for NoCopy<T>
Source§impl<T: RemAssign<U>, U> RemAssign<U> for NoCopy<T>
impl<T: RemAssign<U>, U> RemAssign<U> for NoCopy<T>
Source§fn rem_assign(&mut self, rhs: U)
fn rem_assign(&mut self, rhs: U)
Performs the
%= operation. Read moreSource§impl<T: ShlAssign<U>, U> ShlAssign<U> for NoCopy<T>
impl<T: ShlAssign<U>, U> ShlAssign<U> for NoCopy<T>
Source§fn shl_assign(&mut self, rhs: U)
fn shl_assign(&mut self, rhs: U)
Performs the
<<= operation. Read moreSource§impl<T: ShrAssign<U>, U> ShrAssign<U> for NoCopy<T>
impl<T: ShrAssign<U>, U> ShrAssign<U> for NoCopy<T>
Source§fn shr_assign(&mut self, rhs: U)
fn shr_assign(&mut self, rhs: U)
Performs the
>>= operation. Read moreimpl<T: PartialEq + ?Sized> StructuralPartialEq for NoCopy<T>
Source§impl<T: SubAssign<U>, U> SubAssign<U> for NoCopy<T>
impl<T: SubAssign<U>, U> SubAssign<U> for NoCopy<T>
Source§fn sub_assign(&mut self, rhs: U)
fn sub_assign(&mut self, rhs: U)
Performs the
-= operation. Read moreAuto Trait Implementations§
impl<T> Freeze for NoCopy<T>
impl<T> RefUnwindSafe for NoCopy<T>where
T: RefUnwindSafe + ?Sized,
impl<T> Send for NoCopy<T>
impl<T> Sync for NoCopy<T>
impl<T> Unpin for NoCopy<T>
impl<T> UnsafeUnpin for NoCopy<T>where
T: UnsafeUnpin + ?Sized,
impl<T> UnwindSafe for NoCopy<T>where
T: UnwindSafe + ?Sized,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more