#no-std

macro no-std zeroable_derive

An implementation detail of zeroable

4 releases

✓ Uses Rust 2018 edition

0.2.0 Dec 1, 2019
0.1.2 Nov 30, 2019
0.1.1 Nov 30, 2019
0.1.0 Nov 30, 2019

#310 in #no-std

Download history 11/week @ 2020-02-28 8/week @ 2020-03-06 4/week @ 2020-03-13 24/week @ 2020-03-20 72/week @ 2020-03-27 68/week @ 2020-04-03 63/week @ 2020-04-10 4/week @ 2020-04-17 7/week @ 2020-04-24 10/week @ 2020-05-01 7/week @ 2020-05-08 50/week @ 2020-05-15 49/week @ 2020-05-22 10/week @ 2020-05-29 12/week @ 2020-06-05 10/week @ 2020-06-12

103 downloads per month
Used in zeroable

MIT/Apache

37KB
1K SLoC

Build Status

Provides a derive macro for bytemuck::Zeroable.

Derive Documentation

Here is the documentation for the Zeroable derive macro

Examples

Structs

Here are more struct examples


use zeroable::Zeroable;

#[derive(Debug,PartialEq,Zeroable)]
struct Point3D<T>{
    x:T,
    y:T,
    z:T,
}

assert_eq!( Point3D::zeroed() , Point3D{ x:0, y:0, z:0 } );

Enums

There are some restrictions for enums,documented in the Zeroable macro docs .

Here are more enum examples


use zeroable::Zeroable;

#[derive(Debug,PartialEq,Zeroable)]
#[repr(u8)]
enum Ternary{
    Undefined,
    False,
    True,
}

assert_eq!( Ternary::zeroed() , Ternary::Undefined );

Unions

There are some restrictions for unions,documented in the Zeroable macro docs .

Here are more union examples


use zeroable::Zeroable;

#[derive(Zeroable)]
union Signedness{
    signed:i8,
    unsigned:u8,
}

unsafe{
    assert_eq!( Signedness::zeroed().signed , 0_i8 );
    assert_eq!( Signedness::zeroed().unsigned , 0_u8 );
}

Features

  • "print_type": Slightly improved debugging, shows the type of T in AssertZeroable<T>'s ' Debug implementation

  • "nightly_docs": Makes the documentation examples that require Rust nightly run in doctests, and shows them as tested in the documentation.

#[no_std] support

This crate is #[no_std],and only requires the core library.

Changelog

The changelog is in the "Changelog.md" file.

Minimum Rust version

This crate support Rust back to 1.34.

Dependencies

~395–720KB
~17K SLoC