#macro #no-std #zero #self #type-name #f64 #map-on

no-std hexga_map_on

Define the map_on! macro that can be used to impl a lot of trait quickly using macros

2 releases

Uses new Rust 2024

0.0.10-beta.3 Apr 20, 2025
0.0.10-beta.2 Apr 7, 2025

#889 in Rust patterns

Download history 84/week @ 2025-04-02 42/week @ 2025-04-09 154/week @ 2025-04-16 26/week @ 2025-04-23

306 downloads per month
Used in 6 crates (via hexga_number)

MIT/Apache

6KB
54 lines

HexGa Map On

Define the map_on! macro that can be used to impl a lot of trait quickly using macros

use hexga_map_on::*;

trait Zero
{
    const ZERO : Self;
}

macro_rules! impl_zero {
    ($type_name:ty) => {
        impl Zero for $type_name
        {
            const ZERO : Self = 0 as Self;
        }
    };
}

map_on!
(
    (
        i8, i16, i32, i64, isize,
        u8, u16, u32, u64, usize,
        f32, f64
    ), 
    impl_zero
);

fn main() 
{
    println!("This example impl the Zero trait for a lot of type with ease");
    dbg!(i16::ZERO);

    assert_eq!(i32::ZERO  , 0 );
    assert_eq!(usize::ZERO, 0 );
    assert_eq!(f32::ZERO  , 0.);

    assert_ne!(usize::ZERO, 1);
}

No runtime deps