Skip to main content

Datagram

Struct Datagram 

Source
pub struct Datagram { /* private fields */ }
Expand description

Representation of a datagram

The total length is limited to 128 bits The bits of a telegram are internally enumerated from 0 to 127. A default datagram is expected to be empty (i.e. containing zero bits)

Implementations§

Source§

impl Datagram

Source

pub fn len(&self) -> u8

Source

pub fn is_empty(&self) -> bool

Source

pub fn extract_data(&self, min: u8, max: u8) -> u128

Extract a data slice from the datagram

§Args
  • min - start index (included)
  • max - max index (not included)
§Returns

the extracted value

§Panics

if 0 <= min < max <= len() is violated

§Example

use manchester_code::Datagram;

let datagram = Datagram::new("0-111_10101_00001111");
assert_eq!(0b1111, datagram.extract_data(0, 4));
assert_eq!(0b1111, datagram.extract_data(0, 8));
assert_eq!(0b1111, datagram.extract_data(datagram.len()-5, datagram.len()));
Source

pub fn new(bit_repr: &str) -> Self

Create a new datagram from “binary” string

§Arguments
  • bit_repr - Bit representation as string of zeros and ones. Arbitrary delimiter signs (for readability) are ignored
§Example
use manchester_code::Datagram;

let datagram = Datagram::new("0-111_10101_00001111");

Trait Implementations§

Source§

impl Clone for Datagram

Source§

fn clone(&self) -> Datagram

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Datagram

Source§

impl Debug for Datagram

Source§

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

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

impl Default for Datagram

Source§

fn default() -> Datagram

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

impl Eq for Datagram

Source§

impl Format for Datagram

Source§

fn format(&self, f: Formatter<'_>)

Writes the defmt representation of self to fmt.
Source§

impl Index<u8> for Datagram

Source§

fn index(&self, index: u8) -> &Self::Output

Access the n-th element via index

§Panics
  • if the index is out of range
§Example
use manchester_code::Datagram;

let datagram = Datagram::new("0-111_10101_00001111");
assert_eq!(1, datagram[0]);
assert_eq!(0, datagram[5]);
Source§

type Output = u128

The returned type after indexing.
Source§

impl PartialEq for Datagram

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more

Auto Trait Implementations§

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.