Skip to main content

Primitive

Trait Primitive 

Source
pub trait Primitive:
    Clone
    + Copy
    + Eq
    + PartialEq
    + PartialOrd
    + Ord
    + Debug
    + Display {
    // Required methods
    fn as_i8(self) -> i8;
    fn as_i16(self) -> i16;
    fn as_i32(self) -> i32;
    fn as_i64(self) -> i64;
    fn from_i8(n: i8) -> Self;
    fn from_i16(n: i16) -> Self;
    fn from_i32(n: i32) -> Self;
    fn from_i64(n: i64) -> Self;
    fn checked_add(self, n: Self) -> Option<Self>;
    fn checked_mul(self, n: Self) -> Option<Self>;
}
Expand description

A trait for making x as int_type usable in a generic context.

All of these methods require callers to ensure the cast is correct. However, when debug_assertions is enabled, the casts will result in a panic if they are incorrect.

Because of the extra checks when debug_assertions is enabled, Jiff tries to use these routines wherever possible in lieu of as. The primary downside of using this trait is that it doesn’t work in a const context because Rust does not yet support generics in const.

Required Methods§

Source

fn as_i8(self) -> i8

Source

fn as_i16(self) -> i16

Source

fn as_i32(self) -> i32

Source

fn as_i64(self) -> i64

Source

fn from_i8(n: i8) -> Self

Source

fn from_i16(n: i16) -> Self

Source

fn from_i32(n: i32) -> Self

Source

fn from_i64(n: i64) -> Self

Source

fn checked_add(self, n: Self) -> Option<Self>

Source

fn checked_mul(self, n: Self) -> Option<Self>

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Primitive for i8

Source§

fn as_i8(self) -> i8

Source§

fn as_i16(self) -> i16

Source§

fn as_i32(self) -> i32

Source§

fn as_i64(self) -> i64

Source§

fn from_i8(n: i8) -> Self

Source§

fn from_i16(n: i16) -> Self

Source§

fn from_i32(n: i32) -> Self

Source§

fn from_i64(n: i64) -> Self

Source§

fn checked_add(self, n: i8) -> Option<i8>

Source§

fn checked_mul(self, n: i8) -> Option<i8>

Source§

impl Primitive for i16

Source§

fn as_i8(self) -> i8

Source§

fn as_i16(self) -> i16

Source§

fn as_i32(self) -> i32

Source§

fn as_i64(self) -> i64

Source§

fn from_i8(n: i8) -> Self

Source§

fn from_i16(n: i16) -> Self

Source§

fn from_i32(n: i32) -> Self

Source§

fn from_i64(n: i64) -> Self

Source§

fn checked_add(self, n: i16) -> Option<i16>

Source§

fn checked_mul(self, n: i16) -> Option<i16>

Source§

impl Primitive for i32

Source§

fn as_i8(self) -> i8

Source§

fn as_i16(self) -> i16

Source§

fn as_i32(self) -> i32

Source§

fn as_i64(self) -> i64

Source§

fn from_i8(n: i8) -> Self

Source§

fn from_i16(n: i16) -> Self

Source§

fn from_i32(n: i32) -> Self

Source§

fn from_i64(n: i64) -> Self

Source§

fn checked_add(self, n: i32) -> Option<i32>

Source§

fn checked_mul(self, n: i32) -> Option<i32>

Source§

impl Primitive for i64

Source§

fn as_i8(self) -> i8

Source§

fn as_i16(self) -> i16

Source§

fn as_i32(self) -> i32

Source§

fn as_i64(self) -> i64

Source§

fn from_i8(n: i8) -> Self

Source§

fn from_i16(n: i16) -> Self

Source§

fn from_i32(n: i32) -> Self

Source§

fn from_i64(n: i64) -> Self

Source§

fn checked_add(self, n: i64) -> Option<i64>

Source§

fn checked_mul(self, n: i64) -> Option<i64>

Implementors§