# Derive Macro bevy::core::Zeroable

``````#[derive(Zeroable)]
{
// Attributes available to this derive:
#[zeroable]
}
``````
Expand description

Derive the `Zeroable` trait for a struct

The macro ensures that the struct follows all the the safety requirements for the `Zeroable` trait.

The following constraints need to be satisfied for the macro to succeed

• All fields in the struct must to implement `Zeroable`

### Example

``````#[derive(Copy, Clone, Zeroable)]
#[repr(C)]
struct Test {
a: u16,
b: u16,
}``````

## Custom bounds

Custom bounds for the derived `Zeroable` impl can be given using the `#[zeroable(bound = "")]` helper attribute.

Using this attribute additionally opts-in to “perfect derive” semantics, where instead of adding bounds for each generic type parameter, bounds are added for each field’s type.

### Examples

``````#[derive(Clone, Zeroable)]
#[zeroable(bound = "")]
struct AlwaysZeroable<T> {
a: PhantomData<T>,
}

AlwaysZeroable::<std::num::NonZeroU8>::zeroed();``````
``````#[derive(Clone, Zeroable)]
#[zeroable(bound = "T: Copy")]
struct ZeroableWhenTIsCopy<T> {
a: PhantomData<T>,
}

ZeroableWhenTIsCopy::<String>::zeroed();``````

The restriction that all fields must be Zeroable is still applied, and this is enforced using the mentioned “perfect derive” semantics.

``````#[derive(Clone, Zeroable)]
#[zeroable(bound = "")]
struct ZeroableWhenTIsZeroable<T> {
a: T,
}
ZeroableWhenTIsZeroable::<u32>::zeroed();``````
``ZeroableWhenTIsZeroable::<String>::zeroed();``
{"ft_lang_label":"__label__en","ft_lang_prob":0.5382619,"math_prob":0.47449267,"size":1372,"snap":"2023-40-2023-50","text_gpt3_token_len":355,"char_repetition_ratio":0.17397662,"word_repetition_ratio":0.023121387,"special_character_ratio":0.24854228,"punctuation_ratio":0.20779221,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9731367,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-12-02T15:32:28Z\",\"WARC-Record-ID\":\"<urn:uuid:7c908243-678c-447b-a9e6-3d8c1a514d2c>\",\"Content-Length\":\"7339\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:83ef2484-fc4f-4b8a-8879-5e6e33683710>\",\"WARC-Concurrent-To\":\"<urn:uuid:c5ca5db6-47b9-495a-a1d0-5aa9de7ae892>\",\"WARC-IP-Address\":\"185.199.108.153\",\"WARC-Target-URI\":\"http://dev-docs.bevyengine.org/bevy/core/derive.Zeroable.html\",\"WARC-Payload-Digest\":\"sha1:25JRXLOBKTQMDP4DRL4RTJUJY7FBX7D6\",\"WARC-Block-Digest\":\"sha1:SY76B3F3B3QRHAEB4QIKC4WYNW4YNSA6\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-50/CC-MAIN-2023-50_segments_1700679100427.59_warc_CC-MAIN-20231202140407-20231202170407-00422.warc.gz\"}"}