Giter Club home page Giter Club logo

notzero's Introduction

Rust crates-io api-docs

Provides the nz macro for constructing a std::num::NonZero* from an integer constant.

Example

Usage

#![feature(inline_const)]

use notzero::nz;
use std::num::NonZeroU64;

let two = nz!(2u16); // returns a `NonZeroU16`
assert_eq!(two.get(), 2u16);

// infers the argument's type from the returned `NonZero`
const THREE: NonZeroU64 = nz!(3); 
assert_eq!(THREE.get(), 3u64);

const FOUR: i8 = -4;
let fourz = nz!(FOUR); // returns a `NonZeroI8`
assert_eq!(fourz.get(), -4i8);

Zero argument

#![feature(inline_const)]

const ZERO: u8 = 0;
let _ = notzero::nz!(ZERO);

the above code produces this compile-time error:

error[E0080]: evaluation of `main::_doctest_main_src_lib_rs_27_0::{constant#0}` failed
 --> src/lib.rs:32:9
  |
8 | let _ = notzero::nz!(ZERO);
  |         ^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'passed in a `0` argument', src/lib.rs:8:9
  |
  = note: this error originates in the macro `notzero::nz` (in Nightly builds, run with -Z macro-backtrace for more info)

No-std support

notzero is #![no_std], it can be used anywhere Rust can be used.

Minimum Supported Rust Version

This crate currently requires users to enable the inline_const unstable feature, which means that it requires the nightly compiler.

This crate will support stable Rust once inline_const stabilizes, requiring only the Rust version where the feature is stabilized.

notzero's People

Contributors

rodrimati1992 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.