[][src]Enum cbor_tools::Integer

pub enum Integer {
    U5(ZeroTo23),
    U8(u8),
    U16(u16),
    U32(u32),
    U64(u64),
    N5(ZeroTo23),
    N8(u8),
    N16(u16),
    N32(u32),
    N64(u64),
}

CBOR Integer type

use cbor_tools::{CborType, Integer, Encode};

let val = Integer::from(123);
// This is the CBOR encoding for an 8-bit integer.
assert_eq!(CborType::from(val).encode(), vec![0x18, 0x7B]);

CBOR integers will be represented in "canonical" form if the From<u8 | u32 | u64> impls are used. Non-canonical forms can be created by initializing the struct directly:

let val = Integer::U32(100);
assert_eq!(CborType::from(val).encode(), vec![0x1a, 0, 0, 0, 0x64]);

Note: integers outside the range of [-2^64, 2^64-1] should be encoded as byte strings instead.

Variants

A value between 0 and 23.

U8(u8)

An 8-bit non-negative integer.

U16(u16)

A 16-bit non-negative integer.

U32(u32)

A 32-bit non-negative integer.

U64(u64)

A 64-bit non-negative integer

A small negative integer (between -1 and -24)

N8(u8)

An 8-bit negative integer.

N16(u16)

A 16-bit negative integer.

N32(u32)

A 32-bit negative integer.

N64(u64)

A 64-bit negative integer.

Trait Implementations

impl Clone for Integer[src]

impl Debug for Integer[src]

impl From<i16> for Integer[src]

impl From<i32> for Integer[src]

impl From<i64> for Integer[src]

impl From<i8> for Integer[src]

impl From<u16> for Integer[src]

impl From<u32> for Integer[src]

impl From<u64> for Integer[src]

impl From<u8> for Integer[src]

impl PartialEq<Integer> for Integer[src]

impl StructuralPartialEq for Integer[src]

impl TryFrom<i128> for Integer[src]

type Error = IntOverflowError

The type returned in the event of a conversion error.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.