Struct ConnId

Source
pub struct ConnId(/* private fields */);
Expand description

Value of C_R or C_I, as chosen by ourself or the peer.

Semantically, this is a byte string of some length.

Its legal values are constrained to only contain a single CBOR item that is either a byte string or a number in -24..=23, all in preferred encoding.

Implementations§

Source§

impl ConnId

Source

pub const fn from_int_raw(raw: u8) -> Self

👎Deprecated: This API is only capable of generating a limited sub-set of the supported identifiers.

Construct a ConnId from the result of [cbor_decoder::int_raw], which is a byte that represents a single positive or negative CBOR integer encoded in the 5 bits minor type.

Evolving from u8-only values, this could later interact with the decoder directly.

Source

pub fn from_decoder(decoder: &mut CBORDecoder<'_>) -> Result<Self, CBORError>

Read a connection identifier from a given decoder.

It is an error for the decoder to read anything but a small integer or a byte string, to exceed the maximum allowed ConnId length, or to contain a byte string that should have been encoded as a small integer.

Source

pub fn as_slice(&self) -> &[u8]

The bytes that form the identifier (an arbitrary byte string)

Source

pub fn as_cbor(&self) -> &[u8]

The CBOR encoding of the identifier.

For the 48 compact connection identifiers -24..=23, this is identical to the slice representation:

let c_i = ConnId::from_slice(&[0x04]).unwrap();
assert_eq!(c_i.as_cbor(), &[0x04]);

For other IDs, this contains an extra byte header:

let c_i = ConnId::from_slice(&[0xff]).unwrap();
assert_eq!(c_i.as_cbor(), &[0x41, 0xff]);
Source

pub fn from_slice(input: &[u8]) -> Option<Self>

Try to construct a ConnId from a slice that represents its string value.

This is the inverse of Self::as_slice, and returns None if the identifier is too long (or, if only the compact 48 values are supported, outside of that range).

let c_i = &[0x04];
let c_i = ConnId::from_slice(c_i).unwrap();
assert!(c_i.as_slice() == &[0x04]);

let c_i = ConnId::from_slice(&[0x12, 0x34]).unwrap();
assert!(c_i.as_slice() == &[0x12, 0x34]);

Trait Implementations§

Source§

impl Clone for ConnId

Source§

fn clone(&self) -> ConnId

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ConnId

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ConnId

Source§

fn default() -> ConnId

Returns the “default value” for a type. Read more
Source§

impl PartialEq for ConnId

Source§

fn eq(&self, other: &ConnId) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for ConnId

Source§

impl Eq for ConnId

Source§

impl StructuralPartialEq for ConnId

Auto Trait Implementations§

§

impl Freeze for ConnId

§

impl RefUnwindSafe for ConnId

§

impl Send for ConnId

§

impl Sync for ConnId

§

impl Unpin for ConnId

§

impl UnwindSafe for ConnId

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.