diff --git a/Cargo.lock b/Cargo.lock index 621105cb7..e353f483a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ [root] name = "rust_cast" -version = "0.9.0" +version = "0.9.1" dependencies = [ "byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 0d311fab5..3e3939dad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ repository = "https://github.com/azasypkin/rust-cast" readme = "README.md" license = "MIT" keywords = ["cast", "chromecast", "google"] -version = "0.9.0" +version = "0.9.1" authors = ["Aleh Zasypkin "] exclude = ["protobuf/*"] build = "build.rs" diff --git a/src/channels/connection.rs b/src/channels/connection.rs index 68381cc68..9c057da41 100644 --- a/src/channels/connection.rs +++ b/src/channels/connection.rs @@ -38,12 +38,12 @@ impl<'a, W> ConnectionChannel<'a, W> where W: Read + Write { pub fn connect(&self, destination: S) -> Result<(), Error> where S: Into> { let payload = try!(serde_json::to_string( &proxies::connection::ConnectionRequest { - typ: MESSAGE_TYPE_CONNECT.to_owned(), - user_agent: CHANNEL_USER_AGENT.to_owned(), + typ: MESSAGE_TYPE_CONNECT.to_string(), + user_agent: CHANNEL_USER_AGENT.to_string(), })); self.message_manager.send(CastMessage { - namespace: CHANNEL_NAMESPACE.to_owned(), + namespace: CHANNEL_NAMESPACE.to_string(), source: self.sender.to_string(), destination: destination.into().to_string(), payload: CastMessagePayload::String(payload), @@ -53,12 +53,12 @@ impl<'a, W> ConnectionChannel<'a, W> where W: Read + Write { pub fn disconnect(&self, destination: S) -> Result<(), Error> where S: Into> { let payload = try!(serde_json::to_string( &proxies::connection::ConnectionRequest { - typ: MESSAGE_TYPE_CLOSE.to_owned(), - user_agent: CHANNEL_USER_AGENT.to_owned(), + typ: MESSAGE_TYPE_CLOSE.to_string(), + user_agent: CHANNEL_USER_AGENT.to_string(), })); self.message_manager.send(CastMessage { - namespace: CHANNEL_NAMESPACE.to_owned(), + namespace: CHANNEL_NAMESPACE.to_string(), source: self.sender.to_string(), destination: destination.into().to_string(), payload: CastMessagePayload::String(payload), @@ -73,19 +73,19 @@ impl<'a, W> ConnectionChannel<'a, W> where W: Read + Write { let reply = match message.payload { CastMessagePayload::String(ref payload) => try!( serde_json::from_str::(payload)), - _ => return Err(Error::Internal("Binary payload is not supported!".to_owned())), + _ => return Err(Error::Internal("Binary payload is not supported!".to_string())), }; let message_type = reply.as_object() .and_then(|object| object.get("type")) .and_then(|property| property.as_str()) .unwrap_or("") - .to_owned(); + .to_string(); let response = match message_type.as_ref() { MESSAGE_TYPE_CONNECT => ConnectionResponse::Connect, MESSAGE_TYPE_CLOSE => ConnectionResponse::Close, - _ => ConnectionResponse::NotImplemented(message_type.to_owned(), reply), + _ => ConnectionResponse::NotImplemented(message_type.to_string(), reply), }; Ok(response) diff --git a/src/channels/heartbeat.rs b/src/channels/heartbeat.rs index 03f273e30..5cfa65226 100644 --- a/src/channels/heartbeat.rs +++ b/src/channels/heartbeat.rs @@ -39,11 +39,11 @@ impl<'a, W> HeartbeatChannel<'a, W> where W: Read + Write { pub fn ping(&self) -> Result<(), Error> { let payload = try!(serde_json::to_string( &proxies::heartbeat::HeartBeatRequest { - typ: MESSAGE_TYPE_PING.to_owned() + typ: MESSAGE_TYPE_PING.to_string() })); self.message_manager.send(CastMessage { - namespace: CHANNEL_NAMESPACE.to_owned(), + namespace: CHANNEL_NAMESPACE.to_string(), source: self.sender.to_string(), destination: self.receiver.to_string(), payload: CastMessagePayload::String(payload), @@ -53,11 +53,11 @@ impl<'a, W> HeartbeatChannel<'a, W> where W: Read + Write { pub fn pong(&self) -> Result<(), Error> { let payload = try!(serde_json::to_string( &proxies::heartbeat::HeartBeatRequest { - typ: MESSAGE_TYPE_PONG.to_owned() + typ: MESSAGE_TYPE_PONG.to_string() })); self.message_manager.send(CastMessage { - namespace: CHANNEL_NAMESPACE.to_owned(), + namespace: CHANNEL_NAMESPACE.to_string(), source: self.sender.to_string(), destination: self.receiver.to_string(), payload: CastMessagePayload::String(payload), @@ -72,19 +72,19 @@ impl<'a, W> HeartbeatChannel<'a, W> where W: Read + Write { let reply = match message.payload { CastMessagePayload::String(ref payload) => try!( serde_json::from_str::(payload)), - _ => return Err(Error::Internal("Binary payload is not supported!".to_owned())), + _ => return Err(Error::Internal("Binary payload is not supported!".to_string())), }; let message_type = reply.as_object() .and_then(|object| object.get("type")) .and_then(|property| property.as_str()) .unwrap_or("") - .to_owned(); + .to_string(); let response = match message_type.as_ref() { MESSAGE_TYPE_PING => HeartbeatResponse::Ping, MESSAGE_TYPE_PONG => HeartbeatResponse::Pong, - _ => HeartbeatResponse::NotImplemented(message_type.to_owned(), reply), + _ => HeartbeatResponse::NotImplemented(message_type.to_string(), reply), }; Ok(response) diff --git a/src/channels/media.rs b/src/channels/media.rs index d55f5eff1..41beba6d2 100644 --- a/src/channels/media.rs +++ b/src/channels/media.rs @@ -56,7 +56,7 @@ impl ToString for StreamType { StreamType::Live => "LIVE", }; - stream_type.to_owned() + stream_type.to_string() } } @@ -96,7 +96,7 @@ impl ToString for PlayerState { PlayerState::Paused => "PAUSED", }; - player_state.to_owned() + player_state.to_string() } } @@ -157,7 +157,7 @@ impl ToString for ResumeState { ResumeState::PlaybackPause => "PLAYBACK_PAUSE", }; - resume_state.to_owned() + resume_state.to_string() } } @@ -301,13 +301,13 @@ impl<'a, W> MediaChannel<'a, W> where W: Read + Write { let payload = try!(serde_json::to_string( &proxies::media::GetStatusRequest { - typ: MESSAGE_TYPE_GET_STATUS.to_owned(), + typ: MESSAGE_TYPE_GET_STATUS.to_string(), request_id: request_id, media_session_id: media_session_id, })); try!(self.message_manager.send(CastMessage { - namespace: CHANNEL_NAMESPACE.to_owned(), + namespace: CHANNEL_NAMESPACE.to_string(), source: self.sender.to_string(), destination: destination.into().to_string(), payload: CastMessagePayload::String(payload), @@ -328,7 +328,7 @@ impl<'a, W> MediaChannel<'a, W> where W: Read + Write { if error.request_id == request_id { return Err(Error::Internal( format!("Invalid request ({}).", - error.reason.unwrap_or("Unknown".to_owned()))) + error.reason.unwrap_or("Unknown".to_string()))) ); } }, @@ -357,7 +357,7 @@ impl<'a, W> MediaChannel<'a, W> where W: Read + Write { &proxies::media::MediaRequest { request_id: request_id, session_id: session_id.into().to_string(), - typ: MESSAGE_TYPE_LOAD.to_owned(), + typ: MESSAGE_TYPE_LOAD.to_string(), media: proxies::media::Media { content_id: media.content_id.clone(), @@ -372,7 +372,7 @@ impl<'a, W> MediaChannel<'a, W> where W: Read + Write { })); try!(self.message_manager.send(CastMessage { - namespace: CHANNEL_NAMESPACE.to_owned(), + namespace: CHANNEL_NAMESPACE.to_string(), source: self.sender.to_string(), destination: destination.into().to_string(), payload: CastMessagePayload::String(payload), @@ -410,19 +410,19 @@ impl<'a, W> MediaChannel<'a, W> where W: Read + Write { }, MediaResponse::LoadFailed(error) => { if error.request_id == request_id { - return Err(Error::Internal("Failed to load media.".to_owned())); + return Err(Error::Internal("Failed to load media.".to_string())); } }, MediaResponse::LoadCancelled(error) => { if error.request_id == request_id { return Err( - Error::Internal("Load cancelled by another request.".to_owned())); + Error::Internal("Load cancelled by another request.".to_string())); } }, MediaResponse::InvalidPlayerState(error) => { if error.request_id == request_id { return Err(Error::Internal( - "Load failed because of invalid player state.".to_owned())); + "Load failed because of invalid player state.".to_string())); } }, _ => {} @@ -451,12 +451,12 @@ impl<'a, W> MediaChannel<'a, W> where W: Read + Write { &proxies::media::PlaybackGenericRequest { request_id: request_id, media_session_id: media_session_id, - typ: MESSAGE_TYPE_PAUSE.to_owned(), + typ: MESSAGE_TYPE_PAUSE.to_string(), custom_data: proxies::media::CustomData::new(), })); try!(self.message_manager.send(CastMessage { - namespace: CHANNEL_NAMESPACE.to_owned(), + namespace: CHANNEL_NAMESPACE.to_string(), source: self.sender.to_string(), destination: destination.into().to_string(), payload: CastMessagePayload::String(payload), @@ -484,12 +484,12 @@ impl<'a, W> MediaChannel<'a, W> where W: Read + Write { &proxies::media::PlaybackGenericRequest { request_id: request_id, media_session_id: media_session_id, - typ: MESSAGE_TYPE_PLAY.to_owned(), + typ: MESSAGE_TYPE_PLAY.to_string(), custom_data: proxies::media::CustomData::new(), })); try!(self.message_manager.send(CastMessage { - namespace: CHANNEL_NAMESPACE.to_owned(), + namespace: CHANNEL_NAMESPACE.to_string(), source: self.sender.to_string(), destination: destination.into().to_string(), payload: CastMessagePayload::String(payload), @@ -518,12 +518,12 @@ impl<'a, W> MediaChannel<'a, W> where W: Read + Write { &proxies::media::PlaybackGenericRequest { request_id: request_id, media_session_id: media_session_id, - typ: MESSAGE_TYPE_STOP.to_owned(), + typ: MESSAGE_TYPE_STOP.to_string(), custom_data: proxies::media::CustomData::new(), })); try!(self.message_manager.send(CastMessage { - namespace: CHANNEL_NAMESPACE.to_owned(), + namespace: CHANNEL_NAMESPACE.to_string(), source: self.sender.to_string(), destination: destination.into().to_string(), payload: CastMessagePayload::String(payload), @@ -555,14 +555,14 @@ impl<'a, W> MediaChannel<'a, W> where W: Read + Write { &proxies::media::PlaybackSeekRequest { request_id: request_id, media_session_id: media_session_id, - typ: MESSAGE_TYPE_SEEK.to_owned(), + typ: MESSAGE_TYPE_SEEK.to_string(), current_time: current_time, resume_state: resume_state.map(|s| s.to_string()), custom_data: proxies::media::CustomData::new(), })); try!(self.message_manager.send(CastMessage { - namespace: CHANNEL_NAMESPACE.to_owned(), + namespace: CHANNEL_NAMESPACE.to_string(), source: self.sender.to_string(), destination: destination.into().to_string(), payload: CastMessagePayload::String(payload), @@ -579,14 +579,14 @@ impl<'a, W> MediaChannel<'a, W> where W: Read + Write { let reply = match message.payload { CastMessagePayload::String(ref payload) => try!( serde_json::from_str::(payload)), - _ => return Err(Error::Internal("Binary payload is not supported!".to_owned())), + _ => return Err(Error::Internal("Binary payload is not supported!".to_string())), }; let message_type = reply.as_object() .and_then(|object| object.get("type")) .and_then(|property| property.as_str()) .unwrap_or("") - .to_owned(); + .to_string(); let response = match message_type.as_ref() { MESSAGE_TYPE_MEDIA_STATUS => { @@ -597,9 +597,9 @@ impl<'a, W> MediaChannel<'a, W> where W: Read + Write { StatusEntry { media_session_id: x.media_session_id, media: x.media.as_ref().map(|ref m| Media { - content_id: m.content_id.to_owned(), + content_id: m.content_id.to_string(), stream_type: StreamType::from_str(m.stream_type.as_ref()).unwrap(), - content_type: m.content_type.to_owned(), + content_type: m.content_type.to_string(), duration: m.duration, }), playback_rate: x.playback_rate, @@ -649,7 +649,7 @@ impl<'a, W> MediaChannel<'a, W> where W: Read + Write { reason: reply.reason, }) }, - _ => MediaResponse::NotImplemented(message_type.to_owned(), reply), + _ => MediaResponse::NotImplemented(message_type.to_string(), reply), }; Ok(response) @@ -688,14 +688,14 @@ impl<'a, W> MediaChannel<'a, W> where W: Read + Write { MediaResponse::InvalidPlayerState(error) => { if error.request_id == request_id { return Err(Error::Internal( - "Request failed because of invalid player state.".to_owned())); + "Request failed because of invalid player state.".to_string())); } }, MediaResponse::InvalidRequest(error) => { if error.request_id == request_id { return Err(Error::Internal( format!("Invalid request ({}).", - error.reason.unwrap_or("Unknown".to_owned()))) + error.reason.unwrap_or("Unknown".to_string()))) ); } }, diff --git a/src/channels/receiver.rs b/src/channels/receiver.rs index 6af0b507c..fa36245e0 100644 --- a/src/channels/receiver.rs +++ b/src/channels/receiver.rs @@ -146,7 +146,7 @@ impl FromStr for CastDeviceApp { APP_DEFAULT_MEDIA_RECEIVER_ID | "default" => CastDeviceApp::DefaultMediaReceiver, APP_BACKDROP_ID | "backdrop" => CastDeviceApp::Backdrop, APP_YOUTUBE_ID | "youtube" => CastDeviceApp::YouTube, - custom @ _ => CastDeviceApp::Custom(custom.to_owned()) + custom @ _ => CastDeviceApp::Custom(custom.to_string()) }; Ok(app) @@ -156,10 +156,10 @@ impl FromStr for CastDeviceApp { impl ToString for CastDeviceApp { fn to_string(&self) -> String { match *self { - CastDeviceApp::DefaultMediaReceiver => APP_DEFAULT_MEDIA_RECEIVER_ID.to_owned(), - CastDeviceApp::Backdrop => APP_BACKDROP_ID.to_owned(), - CastDeviceApp::YouTube => APP_YOUTUBE_ID.to_owned(), - CastDeviceApp::Custom(ref app_id) => app_id.to_owned(), + CastDeviceApp::DefaultMediaReceiver => APP_DEFAULT_MEDIA_RECEIVER_ID.to_string(), + CastDeviceApp::Backdrop => APP_BACKDROP_ID.to_string(), + CastDeviceApp::YouTube => APP_YOUTUBE_ID.to_string(), + CastDeviceApp::Custom(ref app_id) => app_id.to_string(), } } } @@ -196,13 +196,13 @@ impl<'a, W> ReceiverChannel<'a, W> where W: Write + Read { let payload = try!(serde_json::to_string( &proxies::receiver::AppLaunchRequest { - typ: MESSAGE_TYPE_LAUNCH.to_owned(), + typ: MESSAGE_TYPE_LAUNCH.to_string(), request_id: request_id, app_id: app.to_string(), })); try!(self.message_manager.send(CastMessage { - namespace: CHANNEL_NAMESPACE.to_owned(), + namespace: CHANNEL_NAMESPACE.to_string(), source: self.sender.to_string(), destination: self.receiver.to_string(), payload: CastMessagePayload::String(payload), @@ -225,7 +225,7 @@ impl<'a, W> ReceiverChannel<'a, W> where W: Write + Read { if error.request_id == request_id { return Err(Error::Internal( format!("Could not run application ({}).", - error.reason.unwrap_or("Unknown".to_owned()))) + error.reason.unwrap_or("Unknown".to_string()))) ); } }, @@ -245,13 +245,13 @@ impl<'a, W> ReceiverChannel<'a, W> where W: Write + Read { let payload = try!(serde_json::to_string( &proxies::receiver::AppStopRequest { - typ: MESSAGE_TYPE_STOP.to_owned(), + typ: MESSAGE_TYPE_STOP.to_string(), request_id: request_id, session_id: session_id.into(), })); try!(self.message_manager.send(CastMessage { - namespace: CHANNEL_NAMESPACE.to_owned(), + namespace: CHANNEL_NAMESPACE.to_string(), source: self.sender.to_string(), destination: self.receiver.to_string(), payload: CastMessagePayload::String(payload), @@ -274,7 +274,7 @@ impl<'a, W> ReceiverChannel<'a, W> where W: Write + Read { if error.request_id == request_id { return Err(Error::Internal( format!("Invalid request ({}).", - error.reason.unwrap_or("Unknown".to_owned()))) + error.reason.unwrap_or("Unknown".to_string()))) ); } }, @@ -295,13 +295,13 @@ impl<'a, W> ReceiverChannel<'a, W> where W: Write + Read { let payload = try!(serde_json::to_string( &proxies::receiver::GetStatusRequest { - typ: MESSAGE_TYPE_GET_STATUS.to_owned(), + typ: MESSAGE_TYPE_GET_STATUS.to_string(), request_id: request_id, })); try!(self.message_manager.send( CastMessage { - namespace: CHANNEL_NAMESPACE.to_owned(), + namespace: CHANNEL_NAMESPACE.to_string(), source: self.sender.to_string(), destination: self.receiver.to_string(), payload: CastMessagePayload::String(payload), @@ -344,7 +344,7 @@ impl<'a, W> ReceiverChannel<'a, W> where W: Write + Read { let payload = try!(serde_json::to_string( &proxies::receiver::SetVolumeRequest { - typ: MESSAGE_TYPE_SET_VOLUME.to_owned(), + typ: MESSAGE_TYPE_SET_VOLUME.to_string(), request_id: request_id, volume: proxies::receiver::Volume { level: volume.level, @@ -353,7 +353,7 @@ impl<'a, W> ReceiverChannel<'a, W> where W: Write + Read { })); try!(self.message_manager.send(CastMessage { - namespace: CHANNEL_NAMESPACE.to_owned(), + namespace: CHANNEL_NAMESPACE.to_string(), source: self.sender.to_string(), destination: self.receiver.to_string(), payload: CastMessagePayload::String(payload), @@ -383,14 +383,14 @@ impl<'a, W> ReceiverChannel<'a, W> where W: Write + Read { let reply = match message.payload { CastMessagePayload::String(ref payload) => try!( serde_json::from_str::(payload)), - _ => return Err(Error::Internal("Binary payload is not supported!".to_owned())), + _ => return Err(Error::Internal("Binary payload is not supported!".to_string())), }; let message_type = reply.as_object() .and_then(|object| object.get("type")) .and_then(|property| property.as_str()) .unwrap_or("") - .to_owned(); + .to_string(); let response = match message_type.as_ref() { MESSAGE_TYPE_RECEIVER_STATUS => { @@ -438,7 +438,7 @@ impl<'a, W> ReceiverChannel<'a, W> where W: Write + Read { reason: reply.reason, }) }, - _ => ReceiverResponse::NotImplemented(message_type.to_owned(), reply), + _ => ReceiverResponse::NotImplemented(message_type.to_string(), reply), }; Ok(response) diff --git a/src/message_manager.rs b/src/message_manager.rs index 050b91a5d..f9fa6a3da 100644 --- a/src/message_manager.rs +++ b/src/message_manager.rs @@ -179,12 +179,12 @@ impl MessageManager where S: Write + Read { debug!("Message received: {:?}", raw_message); Ok(CastMessage { - namespace: raw_message.get_namespace().to_owned(), - source: raw_message.get_source_id().to_owned(), - destination: raw_message.get_destination_id().to_owned(), + namespace: raw_message.get_namespace().to_string(), + source: raw_message.get_source_id().to_string(), + destination: raw_message.get_destination_id().to_string(), payload: match raw_message.get_payload_type() { cast_channel::CastMessage_PayloadType::STRING => CastMessagePayload::String( - raw_message.get_payload_utf8().to_owned()), + raw_message.get_payload_utf8().to_string()), cast_channel::CastMessage_PayloadType::BINARY => CastMessagePayload::Binary( raw_message.get_payload_binary().to_owned()), }