Enum Data

Source
pub enum Data {
    Packet(Packet),
    Datagram(Datagram),
    Telegram(Telegram),
}
Expand description

Data is a type that contains one of the supported VBus protocol data variants.

§Examples

use std::io::Read;

use resol_vbus::{LiveDataReader, Result};

fn print_data_ids<R: Read>(r: R) -> Result<()> {
    let mut ldr = LiveDataReader::new(0, r);

    while let Some(data) = ldr.read_data()? {
        if !data.is_packet() {
            continue;
        }

        println!("{}: {}", data.as_header().timestamp, data.id_string());
    }

    Ok(())
}

Variants§

§

Packet(Packet)

Contains a Packet conforming to VBus protocol version 1.x.

§

Datagram(Datagram)

Contains a Datagram conforming to VBus protocol version 2.x.

§

Telegram(Telegram)

Contains a Telegram conforming to VBus protocol version 3.x.

Implementations§

Source§

impl Data

Source

pub fn is_packet(&self) -> bool

Returns true if the variant is a Packet.

Source

pub fn is_datagram(&self) -> bool

Returns true if the variant is a Packet.

Source

pub fn is_telegram(&self) -> bool

Returns true if the variant is a Packet.

Source

pub fn into_packet(self) -> Packet

Returns the Packet value, consuming the Data value.

§Panics

The function panics if the Data value is no Packet variant.

Source

pub fn into_datagram(self) -> Datagram

Returns the Datagram value, consuming the Data value.

§Panics

The function panics if the Data value is no Datagram variant.

Source

pub fn into_telegram(self) -> Telegram

Returns the Telegram value, consuming the Data value.

§Panics

The function panics if the Data value is no Telegram variant.

Source

pub fn as_header(&self) -> &Header

Returns the Header part of the variant inside this Data.

Source

pub fn as_packet(&self) -> &Packet

Returns the Packet value.

§Panics

The function panics if the Data value is no Packet variant.

Source

pub fn as_datagram(&self) -> &Datagram

Returns the Datagram value.

§Panics

The function panics if the Data value is no Datagram variant.

Source

pub fn as_telegram(&self) -> &Telegram

Returns the Telegram value.

§Panics

The function panics if the Data value is no Telegram variant.

Source

pub fn id_string(&self) -> String

Creates an identification string for the variant inside this Data.

Examples found in repository?
examples/live_data_recorder.rs (line 29)
9fn main() -> Result<()> {
10    async_std::task::block_on(async {
11        // Create an recording file and hand it to a `RecordingWriter`
12        let file = File::create("test.vbus")?;
13        let mut rw = RecordingWriter::new(file);
14
15        // Parse the address of the DL2 to connect to
16        let addr = "192.168.5.217:7053".parse::<SocketAddr>()?;
17
18        let stream = TcpStream::connect(addr).await?;
19
20        let mut hs = TcpClientHandshake::start(stream).await?;
21        hs.send_pass_command("vbus").await?;
22        let stream = hs.send_data_command().await?;
23
24        let (reader, writer) = (&stream, &stream);
25
26        let mut stream = LiveDataStream::new(reader, writer, 0, 0x0020);
27
28        while let Some(data) = stream.receive_any_data(60000).await? {
29            println!("{}", data.id_string());
30
31            // Add `Data` value into `DataSet` to be stored
32            let mut data_set = DataSet::new();
33            data_set.timestamp = data.as_ref().timestamp;
34            data_set.add_data(data);
35
36            // Write the `DataSet` into the `RecordingWriter` for permanent storage
37            rw.write_data_set(&data_set)
38                .expect("Unable to write data set");
39        }
40
41        Ok(())
42    })
43}

Trait Implementations§

Source§

impl AsRef<Header> for Data

Source§

fn as_ref(&self) -> &Header

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Data

Source§

fn clone(&self) -> Data

Returns a copy 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 Data

Source§

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

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

impl From<Datagram> for Data

Source§

fn from(dgram: Datagram) -> Data

Converts to this type from the input type.
Source§

impl From<Packet> for Data

Source§

fn from(packet: Packet) -> Data

Converts to this type from the input type.
Source§

impl From<Telegram> for Data

Source§

fn from(tgram: Telegram) -> Data

Converts to this type from the input type.
Source§

impl IdHash for Data

Source§

fn id_hash<H>(&self, h: &mut H)
where H: Hasher,

Creates an identification hash for this VBus data value.
Source§

impl PartialEq for Data

Source§

fn eq(&self, right: &Data) -> bool

Returns true if two Data values are “identical”.

Each Data variant has a set of fields that make up its “identity”. The PartialEq trait implementation checks those fields for equality and returns true if all of the fields match.

See the descriptions for the Header, Packet, Datagram and Telegram types to find out which fields are considered in each case.

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 PartialOrd for Data

Source§

fn partial_cmp(&self, right: &Data) -> Option<Ordering>

Compares two Data values are “identical”.

Each Data variant has a set of fields that make up its “identity”. The PartialOrd trait implementation compares those fields.

See the descriptions for the Header, Packet, Datagram and Telegram types to find out which fields are considered in each case.

1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations§

§

impl Freeze for Data

§

impl RefUnwindSafe for Data

§

impl Send for Data

§

impl Sync for Data

§

impl Unpin for Data

§

impl UnwindSafe for Data

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.