#[derive(UnsizedCopy)]Expand description
Deriving UnsizedCopy automatically.
UnsizedCopy can be derived on any aggregate type. enums and
unions are inherently Sized types, and UnsizedCopy will simply
require every field to implement Copy on them. For structs, all but
the last field need to implement Copy; the last field needs to
implement UnsizedCopy.
Here’s a simple example:
struct Foo<T: ?Sized> {
a: u32,
b: Bar<T>,
}
// The generated impl with 'derive(UnsizedCopy)':
unsafe impl<T: ?Sized> UnsizedCopy for Foo<T>
where
u32: Copy,
Bar<T>: UnsizedCopy,
{
// This type has the same alignment as 'Foo<T>'.
type Alignment = (u32, <Bar<T> as UnsizedCopy>::Alignment);
fn ptr_with_addr(&self, addr: *const ()) -> *const Self {
self.b.ptr_with_addr(addr) as *const Self
}
}