Struct tinkerforge::converting_receiver::ConvertingReceiver[][src]

pub struct ConvertingReceiver<T: FromByteSlice> { /* fields omitted */ }
Expand description

A wrapper for Receiver, which converts received byte vectors to structured data.

This receiver wraps a Receiver receiving raw bytes. Calling recv or try_recv will call equivalent methods on the wrapped Receiver and then convert the received bytes to a instance of T.

Note

Calling recv will not block indefinitely. Instead the timeout passed to the new method is used for a call of recv_timeout

Type parameters

  • T - Type which is created from received byte vectors. Must implement FromByteSlice

Errors

Returned errors are equivalent to those returned from methods of a Receiver. Additionally errors raised by the brick or bricklet, such as InvalidParameter, FunctionNotSupported and UnknownError will be returned. If the received response can not be interpreted as the result type T, a MalformedPacket error is raised.

Note

If the device is configured to send no response for a result-less setter, the Error SuccessButResponseExpectedIsDisabled will be returned. This indicates, that the request was sent to the device, but no further guarantees can be made.

Implementations

impl<T: FromByteSlice> ConvertingReceiver<T>[src]

pub fn new(
    receiver: Receiver<Result<Vec<u8>, BrickletError>>,
    timeout: Duration
) -> ConvertingReceiver<T>
[src]

Creates a new converting receiver which wraps the given Receiver. recv calls will time out after the given timeout.

pub fn try_recv(&self) -> Result<T, BrickletTryRecvError>[src]

Attempts to return a pending value on this receiver without blocking. This method behaves like try_recv.

Errors

Returns an error on the following conditions:

  • There is no connection to a brick daemon.
  • The brick or bricklet returns an error.
  • The queue was disconnected or currently empty.
  • Response expected was disabled for a result-less setter. This is not an error.

pub fn recv(&self) -> Result<T, BrickletRecvTimeoutError>[src]

Attempts to wait for a value on this receiver, returning an error if the corresponding channel has hung up, or if it waits more than timeout. This method behaves like recv_timeout.

Errors

Returns an error on one of the following conditions:

  • There is no connection to a brick daemon.
  • The brick or bricklet returns an error.
  • The queue was disconnected.
  • Response expected was disabled for a result-less setter. This is not an error.
  • Blocked longer than the configured time out.

pub fn iter(&self) -> Iter<'_, T>

Notable traits for Iter<'a, T>

impl<'a, T: FromByteSlice> Iterator for Iter<'a, T> type Item = T;
[src]

pub fn try_iter(&self) -> TryIter<'_, T>

Notable traits for TryIter<'a, T>

impl<'a, T: FromByteSlice> Iterator for TryIter<'a, T> type Item = T;
[src]

Trait Implementations

impl<'a, T: FromByteSlice> IntoIterator for &'a ConvertingReceiver<T>[src]

type Item = T

The type of the elements being iterated over.

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?

fn into_iter(self) -> Iter<'a, T>

Notable traits for Iter<'a, T>

impl<'a, T: FromByteSlice> Iterator for Iter<'a, T> type Item = T;
[src]

Creates an iterator from a value. Read more

impl<T: FromByteSlice> IntoIterator for ConvertingReceiver<T>[src]

type Item = T

The type of the elements being iterated over.

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?

fn into_iter(self) -> IntoIter<T>

Notable traits for IntoIter<T>

impl<T: FromByteSlice> Iterator for IntoIter<T> type Item = T;
[src]

Creates an iterator from a value. Read more

Auto Trait Implementations

impl<T> !RefUnwindSafe for ConvertingReceiver<T>

impl<T> Send for ConvertingReceiver<T> where
    T: Send

impl<T> !Sync for ConvertingReceiver<T>

impl<T> Unpin for ConvertingReceiver<T> where
    T: Unpin

impl<T> !UnwindSafe for ConvertingReceiver<T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

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]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.