ownable_core/traits/
copy.rs1use crate::traits::{IntoOwned, ToBorrowed, ToOwned};
2use core::num::{NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize};
3use core::num::{NonZeroU128, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize};
4
5impl ToBorrowed<'_> for () {
8 #[inline(always)]
9 fn to_borrowed(&self) -> Self {}
10}
11
12impl ToOwned for () {
13 type Owned = ();
14
15 #[inline(always)]
16 fn to_owned(&self) -> Self::Owned {}
17}
18
19impl IntoOwned for () {
20 type Owned = ();
21
22 #[inline(always)]
23 fn into_owned(self) -> Self::Owned {}
24}
25
26macro_rules! copy_impl {
29 () => {};
30 ($t:ident) => {
31 impl ToBorrowed<'_> for $t {
32 #[inline(always)]
33 fn to_borrowed(&self) -> Self {
34 *self
35 }
36 }
37 impl ToOwned for $t {
38 type Owned = $t;
39
40 #[inline(always)]
41 fn to_owned(&self) -> Self::Owned {
42 *self
43 }
44 }
45 impl IntoOwned for $t {
46 type Owned = $t;
47
48 #[inline(always)]
49 fn into_owned(self) -> Self::Owned {
50 self
51 }
52 }
53 };
54 ($t:ident, $($y:ident),+) => {
55 copy_impl!($t);
56 copy_impl!($($y),+);
57 };
58}
59
60copy_impl!(u8, u16, u32, u64, u128, usize);
61copy_impl!(i8, i16, i32, i64, i128, isize);
62copy_impl!(f32, f64, bool, char);
63
64copy_impl!(
65 NonZeroU8,
66 NonZeroU16,
67 NonZeroU32,
68 NonZeroU64,
69 NonZeroU128,
70 NonZeroUsize
71);
72copy_impl!(
73 NonZeroI8,
74 NonZeroI16,
75 NonZeroI32,
76 NonZeroI64,
77 NonZeroI128,
78 NonZeroIsize
79);