Skip to content

Commit

Permalink
Fix doctests and add basic test for the thread_safe feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
azasypkin committed Jan 10, 2021
1 parent aee2a49 commit cd3ccfc
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ cache:

script:
- cargo build
- cargo test
- cargo build --features thread_safe
- cargo test --features thread_safe

os:
- linux
Expand Down
6 changes: 5 additions & 1 deletion src/channels/receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,11 @@ where
///
/// # Examples
///
/// ```
/// ```no_run
/// use std::str::FromStr;
/// use rust_cast::{CastDevice, channels::receiver::CastDeviceApp};
///
/// # let cast_device = CastDevice::connect_without_host_verification("host", 1234).unwrap();
/// cast_device.receiver.launch_app(&CastDeviceApp::from_str("youtube").unwrap());
/// ```
///
Expand Down
46 changes: 36 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,11 @@ impl<'a> CastDevice<'a> {
///
/// # Examples
///
/// ```
/// let device = CastDevice::connect(args.flag_address.unwrap(), args.flag_port)?;
/// ```no_run
/// use rust_cast::CastDevice;
///
/// let device = CastDevice::connect("192.168.1.2", 8009)?;
/// # Ok::<(), rust_cast::errors::Error>(())
/// ```
///
/// # Arguments
Expand Down Expand Up @@ -115,9 +118,11 @@ impl<'a> CastDevice<'a> {
///
/// # Examples
///
/// ```
/// let device = CastDevice::connect_without_host_verification(
/// args.flag_address.unwrap(), args.flag_port)?;
/// ```no_run
/// use rust_cast::CastDevice;
///
/// let device = CastDevice::connect_without_host_verification("192.168.1.2", 8009)?;
/// # Ok::<(), rust_cast::errors::Error>(())
/// ```
///
/// # Arguments
Expand Down Expand Up @@ -163,13 +168,19 @@ impl<'a> CastDevice<'a> {
///
/// # Examples
///
/// ```
/// ```no_run
/// use rust_cast::ChannelMessage;
///
/// # use rust_cast::CastDevice;
/// # let cast_device = CastDevice::connect_without_host_verification("192.168.1.2", 8009)?;
///
/// match cast_device.receive() {
/// Ok(ChannelMessage::Connection(res)) => debug!("Connection message: {:?}", res),
/// Ok(ChannelMessage::Heartbeat(_)) => cast_device.heartbeat.pong(),
/// .......
/// Err(err) => error!("Error occurred while receiving message {}", err)
/// 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)
/// }
/// # Ok::<(), rust_cast::errors::Error>(())
/// ```
///
/// # Errors
Expand Down Expand Up @@ -241,3 +252,18 @@ impl<'a> CastDevice<'a> {
})
}
}

#[cfg(test)]
pub(crate) mod tests {
#[test]
#[cfg(feature = "thread_safe")]
fn test_thread_safe() {
use crate::CastDevice;

fn is_sync<T: Sync>() {}
fn is_send<T: Send>() {}

is_sync::<CastDevice>();
is_send::<CastDevice>();
}
}
24 changes: 18 additions & 6 deletions src/message_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,26 @@ where
///
/// # Example
///
/// ```
/// ```no_run
/// # use std::net::TcpStream;
/// # use openssl::ssl::{SslConnector, SslMethod, SslStream, SslVerifyMode};
/// # use rust_cast::message_manager::{CastMessage, MessageManager};
/// # let connector = SslConnector::builder(SslMethod::tls()).unwrap().build();
/// # let tcp_stream = TcpStream::connect(("0", 8009)).unwrap();
/// # let ssl_stream = connector.connect("0", tcp_stream).unwrap();
/// # let message_manager = MessageManager::new(ssl_stream);
/// # fn can_handle(message: &CastMessage) -> bool { unimplemented!() }
/// # fn parse(message: &CastMessage) { unimplemented!() }
/// message_manager.receive_find_map(|message| {
/// if !can_handle(message) {
/// return Ok(None);
/// }
/// if !can_handle(message) {
/// return Ok(None);
/// }
///
/// parse(message);
///
/// parse(message)
/// })
/// Ok(Some(()))
/// })?;
/// # Ok::<(), rust_cast::errors::Error>(())
/// ```
///
/// # Arguments
Expand Down

0 comments on commit cd3ccfc

Please sign in to comment.