#associated #identities #constant #zero #const #num-traits #expose

const-identities

Exposes num::{Zero, One} as associated constants

1 unstable release

Uses old Rust 2015

0.1.0 Sep 12, 2018

#10 in #identities

MIT license

4KB
59 lines

Extends the traits from num_traits::identities to use an associated constant.

Examples

#![feature(const_fn)]

use const_identities::ConstZero;

pub struct Newtype<T>(pub T);

impl<T: ConstZero> Newtype<T> {
    pub const fn zero() -> Self {
        Newtype(T::ZERO)
    }
}

assert_eq!(Newtype::<i32>::zero().0, 0);

Dependencies

~275KB