Struct RecordingWriter

Source
pub struct RecordingWriter<W>
where W: Write,
{ /* private fields */ }
Expand description

Allows writing the recorded representation of DataSet values to a Write trait object.

Implementations§

Source§

impl<W> RecordingWriter<W>
where W: Write,

Source

pub fn new(writer: W) -> RecordingWriter<W>

Construct a new RecordingWriter.

Examples found in repository?
examples/live_data_recorder.rs (line 13)
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}
Source

pub fn get_ref(&self) -> &W

Gets a reference to the underlying writer.

Source

pub fn get_mut(&mut self) -> &mut W

Gets a mutable reference to the underlying writer.

Source

pub fn write_data_set(&mut self, data_set: &DataSet) -> Result<(), Error>

Write the recorded representation of the DataSet.

Examples found in repository?
examples/live_data_recorder.rs (line 37)
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<W> Debug for RecordingWriter<W>
where W: Debug + Write,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<W> Freeze for RecordingWriter<W>
where W: Freeze,

§

impl<W> RefUnwindSafe for RecordingWriter<W>
where W: RefUnwindSafe,

§

impl<W> Send for RecordingWriter<W>
where W: Send,

§

impl<W> Sync for RecordingWriter<W>
where W: Sync,

§

impl<W> Unpin for RecordingWriter<W>
where W: Unpin,

§

impl<W> UnwindSafe for RecordingWriter<W>
where W: UnwindSafe,

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> 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.