1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use std::marker::PhantomData;

/// A helper trait to determine whether any arbitrary type is [`Copy`] or not.
///
/// This code attributes to [`nvzqz/impls`](https://github.com/nvzqz/impls).
pub(crate) trait NotCopy {
    const VALUE: bool = false;
}

impl<T> NotCopy for T {}

pub(crate) struct IsCopy<T>(PhantomData<T>);

impl<T: Copy> IsCopy<T> {
    #[allow(dead_code)]
    const VALUE: bool = true;
}

#[cfg(test)]
mod test {
    #![allow(clippy::assertions_on_constants)]

    use super::*;

    #[test]
    fn is_copy() {
        assert!(IsCopy::<usize>::VALUE);
        assert!(IsCopy::<(usize, usize)>::VALUE);
        assert!(!IsCopy::<String>::VALUE);
        assert!(!IsCopy::<(usize, String)>::VALUE);
    }
}