[−][src]Struct rust_cast::message_manager::MessageManager
Static structure that is responsible for (de)serializing and sending/receiving Cast protocol messages.
Methods
impl<S> MessageManager<S> where
S: Write + Read,
[src]
S: Write + Read,
pub fn new(stream: S) -> Self
[src]
pub fn send(&self, message: CastMessage) -> Result<(), Error>
[src]
Sends message
to the Cast Device.
Arguments
message
-CastMessage
instance to be sent to the Cast Device.
pub fn receive(&self) -> Result<CastMessage, Error>
[src]
Waits for the next CastMessage
available. Can also return existing message from the
internal message buffer containing messages that have been received previously, but haven't
been consumed for some reason (e.g. during receive_find_map
call).
Return value
Result
containing parsed CastMessage
or Error
.
pub fn receive_find_map<F, B>(&self, f: F) -> Result<B, Error> where
F: Fn(&CastMessage) -> Result<Option<B>, Error>,
[src]
F: Fn(&CastMessage) -> Result<Option<B>, Error>,
Waits for the next CastMessage
for which f
returns valid mapped value. Messages in which
f
is not interested are placed into internal message buffer and can be later retrieved
with receive
. This method always reads from the stream.
Example
message_manager.receive_find_map(|message| { if !can_handle(message) { return Ok(None); } parse(message) })
Arguments
f
- Function that analyzes and mapsCastMessage
to any other type. If message doesn't look like somethingf
is looking for, thenOk(None)
should be returned so that message is not lost and placed into internal message buffer for later retrieval.
Return value
Result
containing parsed CastMessage
or Error
.
pub fn generate_request_id(&self) -> i32
[src]
Generates unique integer number that is used in some requests to map them with the response.
Return value
Unique (in the scope of this particular MessageManager
instance) integer number.
Auto Trait Implementations
impl<S> !RefUnwindSafe for MessageManager<S>
impl<S> Send for MessageManager<S> where
S: Send,
S: Send,
impl<S> !Sync for MessageManager<S>
impl<S> Unpin for MessageManager<S> where
S: Unpin,
S: Unpin,
impl<S> UnwindSafe for MessageManager<S> where
S: UnwindSafe,
S: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,