Sha256: cb50cc8387466857a46dca6f0368c8be80a5c01036876fe6b10c477880202878

Contents?: true

Size: 1.45 KB

Versions: 17

Compression:

Stored size: 1.45 KB

Contents

/// Helper trait used to add `unsigned()` methods to primitive signed integer
/// types.
///
/// The purpose of this trait is to signal the intent that the sign bit of a
/// signed integer is intended to be discarded and the value is instead
/// understood to be a "bag of bits" where the conversion to an unsigned number
/// is intended to be lossless. This can be used for example when converting a
/// signed integer into a larger width with zero-extension.
pub trait Unsigned {
    /// The unsigned integer for this type which has the same width.
    type Unsigned;

    /// View this signed integer as an unsigned integer of the same width.
    ///
    /// All bits are preserved.
    fn unsigned(self) -> Self::Unsigned;
}

impl Unsigned for i8 {
    type Unsigned = u8;

    #[inline]
    fn unsigned(self) -> u8 {
        self as u8
    }
}

impl Unsigned for i16 {
    type Unsigned = u16;

    #[inline]
    fn unsigned(self) -> u16 {
        self as u16
    }
}

impl Unsigned for i32 {
    type Unsigned = u32;

    #[inline]
    fn unsigned(self) -> u32 {
        self as u32
    }
}

impl Unsigned for i64 {
    type Unsigned = u64;

    #[inline]
    fn unsigned(self) -> u64 {
        self as u64
    }
}

impl Unsigned for i128 {
    type Unsigned = u128;

    #[inline]
    fn unsigned(self) -> u128 {
        self as u128
    }
}

impl Unsigned for isize {
    type Unsigned = usize;

    #[inline]
    fn unsigned(self) -> usize {
        self as usize
    }
}

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/cranelift-entity-0.116.1/src/unsigned.rs
wasmtime-28.0.0 ./ext/cargo-vendor/cranelift-entity-0.115.0/src/unsigned.rs
wasmtime-27.0.0 ./ext/cargo-vendor/cranelift-entity-0.114.0/src/unsigned.rs
wasmtime-26.0.0 ./ext/cargo-vendor/cranelift-entity-0.113.0/src/unsigned.rs
wasmtime-25.0.2 ./ext/cargo-vendor/cranelift-entity-0.112.2/src/unsigned.rs
wasmtime-25.0.1 ./ext/cargo-vendor/cranelift-entity-0.112.1/src/unsigned.rs
wasmtime-25.0.0 ./ext/cargo-vendor/cranelift-entity-0.112.0/src/unsigned.rs
wasmtime-24.0.0 ./ext/cargo-vendor/cranelift-entity-0.111.0/src/unsigned.rs
wasmtime-23.0.2 ./ext/cargo-vendor/cranelift-entity-0.110.2/src/unsigned.rs
wasmtime-22.0.0 ./ext/cargo-vendor/cranelift-entity-0.109.0/src/unsigned.rs
wasmtime-21.0.1 ./ext/cargo-vendor/cranelift-entity-0.108.1/src/unsigned.rs
wasmtime-20.0.2 ./ext/cargo-vendor/cranelift-entity-0.107.2/src/unsigned.rs
wasmtime-20.0.0 ./ext/cargo-vendor/cranelift-entity-0.107.2/src/unsigned.rs
wasmtime-18.0.3 ./ext/cargo-vendor/cranelift-entity-0.105.3/src/unsigned.rs
wasmtime-17.0.1 ./ext/cargo-vendor/cranelift-entity-0.104.1/src/unsigned.rs
wasmtime-17.0.0 ./ext/cargo-vendor/cranelift-entity-0.104.0/src/unsigned.rs
wasmtime-16.0.0 ./ext/cargo-vendor/cranelift-entity-0.103.0/src/unsigned.rs