Skip to content

Commit 5c80fb8

Browse files
committed
impl<A, T> Copy for Aligned<A, T> where ... T: Copy.
1 parent c4abac0 commit 5c80fb8

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/lib.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,33 +29,44 @@
2929
#![deny(warnings)]
3030
#![cfg_attr(not(test), no_std)]
3131

32-
use core::{cmp::Ordering, fmt::{Display, Debug}, hash::{Hash, Hasher}, ops};
32+
use core::{
33+
cmp::Ordering,
34+
fmt::{Debug, Display},
35+
hash::{Hash, Hasher},
36+
ops,
37+
};
3338

3439
use as_slice::{AsMutSlice, AsSlice};
3540

3641
mod sealed;
3742

3843
/// 2-byte alignment
44+
#[derive(Clone, Copy)]
3945
#[repr(align(2))]
4046
pub struct A2;
4147

4248
/// 4-byte alignment
49+
#[derive(Clone, Copy)]
4350
#[repr(align(4))]
4451
pub struct A4;
4552

4653
/// 8-byte alignment
54+
#[derive(Clone, Copy)]
4755
#[repr(align(8))]
4856
pub struct A8;
4957

5058
/// 16-byte alignment
59+
#[derive(Clone, Copy)]
5160
#[repr(align(16))]
5261
pub struct A16;
5362

5463
/// 32-byte alignment
64+
#[derive(Clone, Copy)]
5565
#[repr(align(32))]
5666
pub struct A32;
5767

5868
/// 64-byte alignment
69+
#[derive(Clone, Copy)]
5970
#[repr(align(64))]
6071
pub struct A64;
6172

@@ -146,6 +157,13 @@ where
146157
}
147158
}
148159

160+
impl<A, T> Copy for Aligned<A, T>
161+
where
162+
A: sealed::Alignment,
163+
T: Copy,
164+
{
165+
}
166+
149167
impl<A, T> Default for Aligned<A, T>
150168
where
151169
A: sealed::Alignment,
@@ -193,7 +211,8 @@ impl<A, T> Eq for Aligned<A, T>
193211
where
194212
A: sealed::Alignment,
195213
T: Eq,
196-
{}
214+
{
215+
}
197216

198217
impl<A, T> Hash for Aligned<A, T>
199218
where

src/sealed.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pub trait Alignment {}
1+
pub trait Alignment: Copy {}
22

33
impl Alignment for super::A2 {}
44
impl Alignment for super::A4 {}

0 commit comments

Comments
 (0)