[−][src]Struct bcder::int::Integer
A BER encoded integer.
As integers are variable length in BER, this type is just a simple wrapper
atop the underlying Bytes
value containing the raw content. A value of
this type is a signed integer. If a value is defined as an unsigned
integer, i.e., as INTEGER (0..MAX)
, you should use the sibling type
Unsigned
instead.
In addition to these two generic types, the content decoders also provide
methods to parse integers into native integer types such as i8
. If the
range of such a type is obviously enough, you might want to consider
using these methods instead.
BER Encoding
In BER, an INTEGER is encoded as a primitive value with the content octets providing a variable-length, big-endian, two‘s complement byte sequence of that integer. Thus, the most-significant bit of the first octet serves as the sign bit.
Implementations
impl Integer
[src]
pub fn take_from<S: Source>(
cons: &mut Constructed<'_, S>
) -> Result<Self, S::Err>
[src]
cons: &mut Constructed<'_, S>
) -> Result<Self, S::Err>
Takes a single signed integer from the beginning of an encoded value.
This requires the next value in cons
to be a primitive value with
a correctly encoded signed integer.
pub fn from_primitive<S: Source>(
prim: &mut Primitive<'_, S>
) -> Result<Self, S::Err>
[src]
prim: &mut Primitive<'_, S>
) -> Result<Self, S::Err>
Constructs a signed integer from the content of a primitive value.
pub fn i8_from_primitive<S: Source>(
prim: &mut Primitive<'_, S>
) -> Result<i8, S::Err>
[src]
prim: &mut Primitive<'_, S>
) -> Result<i8, S::Err>
Constructs an i8
from the content of a primitive value.
pub fn i16_from_primitive<S: Source>(
prim: &mut Primitive<'_, S>
) -> Result<i16, S::Err>
[src]
prim: &mut Primitive<'_, S>
) -> Result<i16, S::Err>
Constructs an i16
from the content of a primitive value.
pub fn i32_from_primitive<S: Source>(
prim: &mut Primitive<'_, S>
) -> Result<i32, S::Err>
[src]
prim: &mut Primitive<'_, S>
) -> Result<i32, S::Err>
Constructs an i32
from the content of a primitive value.
pub fn i64_from_primitive<S: Source>(
prim: &mut Primitive<'_, S>
) -> Result<i64, S::Err>
[src]
prim: &mut Primitive<'_, S>
) -> Result<i64, S::Err>
Constructs an i64
from the content of a primitive value.
pub fn i128_from_primitive<S: Source>(
prim: &mut Primitive<'_, S>
) -> Result<i128, S::Err>
[src]
prim: &mut Primitive<'_, S>
) -> Result<i128, S::Err>
Constructs an i128
from the content of a primitive value.
pub fn into_bytes(self) -> Bytes
[src]
Trades the integer into a bytes value with the raw content octets.
pub fn as_slice(&self) -> &[u8]
[src]
Returns a bytes slice with the raw content.
pub fn is_zero(&self) -> bool
[src]
Returns whether the number is zero.
pub fn is_positive(&self) -> bool
[src]
Returns whether the integer is positive.
Also returns false
if the number is zero.
pub fn is_negative(&self) -> bool
[src]
Returns whether the integer is negative.
Also returns false
if the number is zero.
Trait Implementations
impl AsRef<[u8]> for Integer
[src]
impl AsRef<Bytes> for Integer
[src]
impl AsRef<Integer> for Unsigned
[src]
impl Clone for Integer
[src]
impl Debug for Integer
[src]
impl Eq for Integer
[src]
impl From<i128> 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<u128> 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 Hash for Integer
[src]
pub fn hash<H: Hasher>(&self, h: &mut H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for Integer
[src]
pub fn cmp(&self, other: &Self) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl PartialEq<Integer> for Integer
[src]
pub fn eq(&self, other: &Self) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialEq<Unsigned> for Integer
[src]
pub fn eq(&self, other: &Unsigned) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialOrd<Integer> for Integer
[src]
pub fn partial_cmp(&self, other: &Self) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<'a> PrimitiveContent for &'a Integer
[src]
pub const TAG: Tag
[src]
pub fn encoded_len(&self, _mode: Mode) -> usize
[src]
pub fn write_encoded<W: Write>(
&self,
_mode: Mode,
target: &mut W
) -> Result<(), Error>
[src]
&self,
_mode: Mode,
target: &mut W
) -> Result<(), Error>
pub fn to_encoded_bytes(&self, mode: Mode) -> Bytes
[src]
pub fn encode(self) -> Primitive<Self>
[src]
pub fn encode_as(self, tag: Tag) -> Primitive<Self>
[src]
pub fn encode_ref(&self) -> Primitive<&Self>
[src]
pub fn encode_ref_as(&self, tag: Tag) -> Primitive<&Self>
[src]
impl<'a> TryFrom<&'a Integer> for i8
[src]
type Error = OverflowError
The type returned in the event of a conversion error.
pub fn try_from(val: &'a Integer) -> Result<i8, Self::Error>
[src]
impl<'a> TryFrom<&'a Integer> for i16
[src]
type Error = OverflowError
The type returned in the event of a conversion error.
pub fn try_from(val: &'a Integer) -> Result<i16, Self::Error>
[src]
impl<'a> TryFrom<&'a Integer> for i32
[src]
type Error = OverflowError
The type returned in the event of a conversion error.
pub fn try_from(val: &'a Integer) -> Result<i32, Self::Error>
[src]
impl<'a> TryFrom<&'a Integer> for i64
[src]
type Error = OverflowError
The type returned in the event of a conversion error.
pub fn try_from(val: &'a Integer) -> Result<i64, Self::Error>
[src]
impl<'a> TryFrom<&'a Integer> for i128
[src]
type Error = OverflowError
The type returned in the event of a conversion error.
pub fn try_from(val: &'a Integer) -> Result<i128, Self::Error>
[src]
impl<'a> TryFrom<&'a Integer> for u8
[src]
type Error = OverflowError
The type returned in the event of a conversion error.
pub fn try_from(val: &'a Integer) -> Result<u8, Self::Error>
[src]
impl<'a> TryFrom<&'a Integer> for u16
[src]
type Error = OverflowError
The type returned in the event of a conversion error.
pub fn try_from(val: &'a Integer) -> Result<u16, Self::Error>
[src]
impl<'a> TryFrom<&'a Integer> for u32
[src]
type Error = OverflowError
The type returned in the event of a conversion error.
pub fn try_from(val: &'a Integer) -> Result<u32, Self::Error>
[src]
impl<'a> TryFrom<&'a Integer> for u64
[src]
type Error = OverflowError
The type returned in the event of a conversion error.
pub fn try_from(val: &'a Integer) -> Result<u64, Self::Error>
[src]
impl<'a> TryFrom<&'a Integer> for u128
[src]
type Error = OverflowError
The type returned in the event of a conversion error.
pub fn try_from(val: &'a Integer) -> Result<u128, Self::Error>
[src]
impl TryFrom<Integer> for i8
[src]
type Error = OverflowError
The type returned in the event of a conversion error.
pub fn try_from(val: Integer) -> Result<i8, Self::Error>
[src]
impl TryFrom<Integer> for i16
[src]
type Error = OverflowError
The type returned in the event of a conversion error.
pub fn try_from(val: Integer) -> Result<i16, Self::Error>
[src]
impl TryFrom<Integer> for i32
[src]
type Error = OverflowError
The type returned in the event of a conversion error.
pub fn try_from(val: Integer) -> Result<i32, Self::Error>
[src]
impl TryFrom<Integer> for i64
[src]
type Error = OverflowError
The type returned in the event of a conversion error.
pub fn try_from(val: Integer) -> Result<i64, Self::Error>
[src]
impl TryFrom<Integer> for i128
[src]
type Error = OverflowError
The type returned in the event of a conversion error.
pub fn try_from(val: Integer) -> Result<i128, Self::Error>
[src]
impl TryFrom<Integer> for u8
[src]
type Error = OverflowError
The type returned in the event of a conversion error.
pub fn try_from(val: Integer) -> Result<u8, Self::Error>
[src]
impl TryFrom<Integer> for u16
[src]
type Error = OverflowError
The type returned in the event of a conversion error.
pub fn try_from(val: Integer) -> Result<u16, Self::Error>
[src]
impl TryFrom<Integer> for u32
[src]
type Error = OverflowError
The type returned in the event of a conversion error.
pub fn try_from(val: Integer) -> Result<u32, Self::Error>
[src]
impl TryFrom<Integer> for u64
[src]
type Error = OverflowError
The type returned in the event of a conversion error.
pub fn try_from(val: Integer) -> Result<u64, Self::Error>
[src]
impl TryFrom<Integer> for u128
[src]
Auto Trait Implementations
impl RefUnwindSafe for Integer
[src]
impl Send for Integer
[src]
impl Sync for Integer
[src]
impl Unpin for Integer
[src]
impl UnwindSafe for Integer
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,