Skip to content

Easy, safe, and fully zero-cost NonZero constants

License

Notifications You must be signed in to change notification settings

thomcc/nonzero_lit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nonzero_lit

Build Status Docs Latest Version Minimum Rust Version

A small macro crate providing safe, easy, and fully zero-cost way to construct constant or literal instances of the NonZero* types from core::num.

Features

Usage

Add this to your Cargo.toml:

[dependencies]
nonzero_lit = "0.1"

Examples

let x = nonzero_lit::i32!(4);
assert_eq!(x.get(), 4);
const FERRIS: core::num::NonZeroU32 = nonzero_lit::u32!(0xf34415);
assert_eq!(FERRIS.get(), 0xf34415);
use core::num::NonZeroU64;
const MASK: NonZeroU64 = nonzero_lit::u64!(0xffff_00ff_00ff_0f0f);
const MASKEE: NonZeroU64 = nonzero_lit::u64!(0xaabb_ccdd_eeff_1122);
const MASKED: NonZeroU64 = nonzero_lit::u64!(MASK.get() & MASKEE.get());
assert_eq!(MASKED.get(), 0xaabb_00dd_00ff_0102_u64);

License

Public domain, as explained here. If that's unacceptable, it's also available under either the Apache-2.0 or MIT licenses, at your option.

About

Easy, safe, and fully zero-cost NonZero constants

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages