Skip to main content

NoCopy

Struct NoCopy 

Source
#[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: T

Avoid use x.0 inside the closure, as the closure can capture fields

Trying *{x} or {x}.0?

Implementations§

Source§

impl<T: Copy> NoCopy<T>

Source

pub const fn from_copy(value: T) -> Self

Only from can copy types.

§Examples
use no_copy::NoCopy;

assert_eq!(NoCopy::from_copy(2), NoCopy(2));
use no_copy::NoCopy;

let non_copy = String::new();
let _ = NoCopy::from_copy(non_copy);
Source§

impl<T: Copy> NoCopy<T>

Source

pub const fn into_inner(this: Self) -> T

Trait Implementations§

Source§

impl<T: Add<U>, U> Add<U> for NoCopy<T>

Source§

type Output = <T as Add<U>>::Output

The resulting type after applying the + operator.
Source§

fn add(self, rhs: U) -> Self::Output

Performs the + operation. Read more
Source§

impl<T: AddAssign<U>, U> AddAssign<U> for NoCopy<T>

Source§

fn add_assign(&mut self, rhs: U)

Performs the += operation. Read more
Source§

impl<U, T: AsMut<U>> AsMut<U> for NoCopy<T>

Source§

fn as_mut(&mut self) -> &mut U

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<U, T: AsRef<U>> AsRef<U> for NoCopy<T>

Source§

fn as_ref(&self) -> &U

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T: ?Sized + Binary> Binary for NoCopy<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: BitAnd<U>, U> BitAnd<U> for NoCopy<T>

Source§

type Output = <T as BitAnd<U>>::Output

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: U) -> Self::Output

Performs the & operation. Read more
Source§

impl<T: BitAndAssign<U>, U> BitAndAssign<U> for NoCopy<T>

Source§

fn bitand_assign(&mut self, rhs: U)

Performs the &= operation. Read more
Source§

impl<T: BitOr<U>, U> BitOr<U> for NoCopy<T>

Source§

type Output = <T as BitOr<U>>::Output

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: U) -> Self::Output

Performs the | operation. Read more
Source§

impl<T: BitOrAssign<U>, U> BitOrAssign<U> for NoCopy<T>

Source§

fn bitor_assign(&mut self, rhs: U)

Performs the |= operation. Read more
Source§

impl<T: BitXor<U>, U> BitXor<U> for NoCopy<T>

Source§

type Output = <T as BitXor<U>>::Output

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: U) -> Self::Output

Performs the ^ operation. Read more
Source§

impl<T: BitXorAssign<U>, U> BitXorAssign<U> for NoCopy<T>

Source§

fn bitxor_assign(&mut self, rhs: U)

Performs the ^= operation. Read more
Source§

impl<T: ?Sized> Borrow<T> for NoCopy<T>

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T: ?Sized> BorrowMut<T> for NoCopy<T>

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<H: BuildHasher> BuildHasher for NoCopy<H>

Source§

type Hasher = <H as BuildHasher>::Hasher

Type of the hasher that will be created.
Source§

fn hash_one<T: Hash>(&self, x: T) -> u64
where Self: Sized, Self::Hasher: Hasher,

Calculates the hash of a single value. Read more
Source§

fn build_hasher(&self) -> Self::Hasher

Creates a new hasher. Read more
Source§

impl<T: Clone + ?Sized> Clone for NoCopy<T>

Source§

fn clone(&self) -> NoCopy<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: ?Sized + Debug> Debug for NoCopy<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Default + ?Sized> Default for NoCopy<T>

Source§

fn default() -> NoCopy<T>

Returns the “default value” for a type. Read more
Source§

impl<T: ?Sized> Deref for NoCopy<T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T: ?Sized> DerefMut for NoCopy<T>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<T: ?Sized + Display> Display for NoCopy<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Div<U>, U> Div<U> for NoCopy<T>

Source§

type Output = <T as Div<U>>::Output

The resulting type after applying the / operator.
Source§

fn div(self, rhs: U) -> Self::Output

Performs the / operation. Read more
Source§

impl<T: DivAssign<U>, U> DivAssign<U> for NoCopy<T>

Source§

fn div_assign(&mut self, rhs: U)

Performs the /= operation. Read more
Source§

impl<T: Eq + ?Sized> Eq for NoCopy<T>

Source§

impl<T: Extend<A>, A> Extend<A> for NoCopy<T>

Source§

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)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

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<T> From<T> for NoCopy<T>

Source§

fn from(value: T) -> Self

Converts to this type from the input type.
Source§

impl<T: Hash + ?Sized> Hash for NoCopy<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<H: ?Sized + Hasher> Hasher for NoCopy<H>

Source§

fn finish(&self) -> u64

Returns the hash value for the values written so far. Read more
Source§

fn write(&mut self, bytes: &[u8])

Writes some data into this Hasher. Read more
Source§

fn write_u8(&mut self, i: u8)

Writes a single u8 into this hasher.
Source§

fn write_u16(&mut self, i: u16)

Writes a single u16 into this hasher.
Source§

fn write_u32(&mut self, i: u32)

Writes a single u32 into this hasher.
Source§

fn write_u64(&mut self, i: u64)

Writes a single u64 into this hasher.
Source§

fn write_u128(&mut self, i: u128)

Writes a single u128 into this hasher.
Source§

fn write_usize(&mut self, i: usize)

Writes a single usize into this hasher.
Source§

fn write_i8(&mut self, i: i8)

Writes a single i8 into this hasher.
Source§

fn write_i16(&mut self, i: i16)

Writes a single i16 into this hasher.
Source§

fn write_i32(&mut self, i: i32)

Writes a single i32 into this hasher.
Source§

fn write_i64(&mut self, i: i64)

Writes a single i64 into this hasher.
Source§

fn write_i128(&mut self, i: i128)

Writes a single i128 into this hasher.
Source§

fn write_isize(&mut self, i: isize)

Writes a single isize into this hasher.
Source§

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§

fn write_str(&mut self, s: &str)

🔬This is a nightly-only experimental API. (hasher_prefixfree_extras)
Writes a single str into this hasher. Read more
Source§

impl<T: Index<U>, U> Index<U> for NoCopy<T>

Source§

type Output = <T as Index<U>>::Output

The returned type after indexing.
Source§

fn index(&self, index: U) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T: IndexMut<U>, U> IndexMut<U> for NoCopy<T>

Source§

fn index_mut(&mut self, index: U) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<T: IntoIterator> IntoIterator for NoCopy<T>

Source§

type Item = <T as IntoIterator>::Item

The type of the elements being iterated over.
Source§

type IntoIter = <T as IntoIterator>::IntoIter

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T: ?Sized + LowerExp> LowerExp for NoCopy<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: ?Sized + LowerHex> LowerHex for NoCopy<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Mul<U>, U> Mul<U> for NoCopy<T>

Source§

type Output = <T as Mul<U>>::Output

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: U) -> Self::Output

Performs the * operation. Read more
Source§

impl<T: MulAssign<U>, U> MulAssign<U> for NoCopy<T>

Source§

fn mul_assign(&mut self, rhs: U)

Performs the *= operation. Read more
Source§

impl<T: Neg> Neg for NoCopy<T>

Source§

type Output = <T as Neg>::Output

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<T: Not> Not for NoCopy<T>

Source§

type Output = <T as Not>::Output

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more
Source§

impl<T: ?Sized + Octal> Octal for NoCopy<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Ord + ?Sized> Ord for NoCopy<T>

Source§

fn cmp(&self, other: &NoCopy<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T: PartialEq + ?Sized> PartialEq for NoCopy<T>

Source§

fn eq(&self, other: &NoCopy<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: ?Sized + PartialEq> PartialEq<T> for NoCopy<T>

Source§

fn eq(&self, other: &T) -> bool

Tests for self and other values to be equal, and is used by ==.
Source§

fn ne(&self, other: &T) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialOrd + ?Sized> PartialOrd for NoCopy<T>

Source§

fn partial_cmp(&self, other: &NoCopy<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T: ?Sized + PartialOrd> PartialOrd<T> for NoCopy<T>

Source§

fn partial_cmp(&self, other: &T) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
Source§

fn lt(&self, other: &T) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
Source§

fn le(&self, other: &T) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
Source§

fn gt(&self, other: &T) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
Source§

fn ge(&self, other: &T) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T: ?Sized + Pointer> Pointer for NoCopy<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Product<A>, A> Product<A> for NoCopy<T>

Source§

fn product<I: Iterator<Item = A>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by multiplying the items.
Source§

impl<T: RangeBounds<R>, R> RangeBounds<R> for NoCopy<T>

Source§

fn contains<U>(&self, item: &U) -> bool
where R: PartialOrd<U>, U: ?Sized + PartialOrd<R>,

Returns true if item is contained in the range. Read more
Source§

fn end_bound(&self) -> Bound<&R>

End index bound. Read more
Source§

fn start_bound(&self) -> Bound<&R>

Start index bound. Read more
Source§

fn is_empty(&self) -> bool
where T: PartialOrd,

🔬This is a nightly-only experimental API. (range_bounds_is_empty)
Returns true if the range contains no items. One-sided ranges (RangeFrom, etc) always return false. Read more
Source§

impl<T: Rem<U>, U> Rem<U> for NoCopy<T>

Source§

type Output = <T as Rem<U>>::Output

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: U) -> Self::Output

Performs the % operation. Read more
Source§

impl<T: RemAssign<U>, U> RemAssign<U> for NoCopy<T>

Source§

fn rem_assign(&mut self, rhs: U)

Performs the %= operation. Read more
Source§

impl<T: Shl<U>, U> Shl<U> for NoCopy<T>

Source§

type Output = <T as Shl<U>>::Output

The resulting type after applying the << operator.
Source§

fn shl(self, rhs: U) -> Self::Output

Performs the << operation. Read more
Source§

impl<T: ShlAssign<U>, U> ShlAssign<U> for NoCopy<T>

Source§

fn shl_assign(&mut self, rhs: U)

Performs the <<= operation. Read more
Source§

impl<T: Shr<U>, U> Shr<U> for NoCopy<T>

Source§

type Output = <T as Shr<U>>::Output

The resulting type after applying the >> operator.
Source§

fn shr(self, rhs: U) -> Self::Output

Performs the >> operation. Read more
Source§

impl<T: ShrAssign<U>, U> ShrAssign<U> for NoCopy<T>

Source§

fn shr_assign(&mut self, rhs: U)

Performs the >>= operation. Read more
Source§

impl<T: PartialEq + ?Sized> StructuralPartialEq for NoCopy<T>

Source§

impl<T: Sub<U>, U> Sub<U> for NoCopy<T>

Source§

type Output = <T as Sub<U>>::Output

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: U) -> Self::Output

Performs the - operation. Read more
Source§

impl<T: SubAssign<U>, U> SubAssign<U> for NoCopy<T>

Source§

fn sub_assign(&mut self, rhs: U)

Performs the -= operation. Read more
Source§

impl<T: Sum<A>, A> Sum<A> for NoCopy<T>

Source§

fn sum<I: Iterator<Item = A>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl<T: ?Sized + UpperExp> UpperExp for NoCopy<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: ?Sized + UpperHex> UpperHex for NoCopy<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: ?Sized + Write> Write for NoCopy<T>

Source§

fn write_str(&mut self, s: &str) -> Result

Writes a string slice into this writer, returning whether the write succeeded. Read more
Source§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result

Glue for usage of the write! macro with implementors of this trait. Read more
Source§

fn write_char(&mut self, c: char) -> Result

Writes a char into this writer, returning whether the write succeeded. Read more

Auto Trait Implementations§

§

impl<T> Freeze for NoCopy<T>
where T: Freeze + ?Sized,

§

impl<T> RefUnwindSafe for NoCopy<T>
where T: RefUnwindSafe + ?Sized,

§

impl<T> Send for NoCopy<T>
where T: Send + ?Sized,

§

impl<T> Sync for NoCopy<T>
where T: Sync + ?Sized,

§

impl<T> Unpin for NoCopy<T>
where T: Unpin + ?Sized,

§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.