Struct rust_cast::CastDevice

source ·
pub struct CastDevice<'a> {
    pub connection: ConnectionChannel<'a, StreamOwned<ClientConnection, TcpStream>>,
    pub heartbeat: HeartbeatChannel<'a, StreamOwned<ClientConnection, TcpStream>>,
    pub media: MediaChannel<'a, StreamOwned<ClientConnection, TcpStream>>,
    pub receiver: ReceiverChannel<'a, StreamOwned<ClientConnection, TcpStream>>,
    /* private fields */
}
Expand description

Structure that manages connection to a cast device.

Fields§

§connection: ConnectionChannel<'a, StreamOwned<ClientConnection, TcpStream>>

Channel that manages connection responses/requests.

§heartbeat: HeartbeatChannel<'a, StreamOwned<ClientConnection, TcpStream>>

Channel that allows connection to stay alive (via ping-pong requests/responses).

§media: MediaChannel<'a, StreamOwned<ClientConnection, TcpStream>>

Channel that manages various media stuff.

§receiver: ReceiverChannel<'a, StreamOwned<ClientConnection, TcpStream>>

Channel that manages receiving platform (e.g. Chromecast).

Implementations§

source§

impl<'a> CastDevice<'a>

source

pub fn connect<S>(host: S, port: u16) -> Result<CastDevice<'a>, Error>
where S: Into<Cow<'a, str>>,

Connects to the cast device using host name and port.

§Examples
use rust_cast::CastDevice;

let device = CastDevice::connect("192.168.1.2", 8009)?;
§Arguments
  • host - Cast device host name.
  • port - Cast device port number.
§Errors

This method may fail if connection to Cast device can’t be established for some reason (e.g. wrong host name or port).

§Return value

Instance of CastDevice that allows you to manage connection.

source

pub fn connect_without_host_verification<S>( host: S, port: u16 ) -> Result<CastDevice<'a>, Error>
where S: Into<Cow<'a, str>>,

Connects to the cast device using host name and port without host verification. Use on your own risk!

§Examples
use rust_cast::CastDevice;

let device = CastDevice::connect_without_host_verification("192.168.1.2", 8009)?;
§Arguments
  • host - Cast device host name.
  • port - Cast device port number.
§Errors

This method may fail if connection to Cast device can’t be established for some reason (e.g. wrong host name or port).

§Return value

Instance of CastDevice that allows you to manage connection.

source

pub fn receive(&self) -> Result<ChannelMessage, Error>

Waits for any message returned by cast device (e.g. Chromecast) and returns its parsed version.

§Examples
use rust_cast::ChannelMessage;


match cast_device.receive() {
    Ok(ChannelMessage::Connection(res)) => log::debug!("Connection message: {:?}", res),
    Ok(ChannelMessage::Heartbeat(_)) => cast_device.heartbeat.pong()?,
    Ok(_) => {},
    Err(err) => log::error!("Error occurred while receiving message {}", err)
}
§Errors

Usually fails if message returned by device can’t be parsed.

§Returned values

Parsed channel message.

Auto Trait Implementations§

§

impl<'a> Freeze for CastDevice<'a>

§

impl<'a> !RefUnwindSafe for CastDevice<'a>

§

impl<'a> !Send for CastDevice<'a>

§

impl<'a> !Sync for CastDevice<'a>

§

impl<'a> Unpin for CastDevice<'a>

§

impl<'a> !UnwindSafe for CastDevice<'a>

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

§

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

§

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.