From b8a031c29ba123a57a9c85714d0531adf4599ae4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 18 May 2016 11:29:57 +0300 Subject: [PATCH] Use Option<&str> instead of Option for set_uri() There is no reason to require a heap-allocated String here. --- src/rsfilesink.rs | 4 ++-- src/rsfilesrc.rs | 4 ++-- src/rshttpsrc.rs | 4 ++-- src/rssink.rs | 4 ++-- src/rssource.rs | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/rsfilesink.rs b/src/rsfilesink.rs index 5af81aec..0d82f228 100644 --- a/src/rsfilesink.rs +++ b/src/rsfilesink.rs @@ -50,14 +50,14 @@ impl FileSink { } impl Sink for FileSink { - fn set_uri(&mut self, uri_str: &Option) -> bool { + fn set_uri(&mut self, uri_str: &Option<&str>) -> bool { match *uri_str { None => { self.location = None; return true; }, Some(ref uri_str) => { - let uri_parsed = Url::parse(uri_str.as_str()); + let uri_parsed = Url::parse(uri_str); match uri_parsed { Ok(u) => { match u.to_file_path().ok() { diff --git a/src/rsfilesrc.rs b/src/rsfilesrc.rs index e766963b..1350be79 100644 --- a/src/rsfilesrc.rs +++ b/src/rsfilesrc.rs @@ -51,14 +51,14 @@ impl FileSrc { } impl Source for FileSrc { - fn set_uri(&mut self, uri_str: &Option) -> bool { + fn set_uri(&mut self, uri_str: &Option<&str>) -> bool { match *uri_str { None => { self.location = None; return true; }, Some(ref uri_str) => { - let uri_parsed = Url::parse(uri_str.as_str()); + let uri_parsed = Url::parse(uri_str); match uri_parsed { Ok(u) => { match u.to_file_path().ok() { diff --git a/src/rshttpsrc.rs b/src/rshttpsrc.rs index c86fcd30..12b859db 100644 --- a/src/rshttpsrc.rs +++ b/src/rshttpsrc.rs @@ -123,7 +123,7 @@ impl HttpSrc { } impl Source for HttpSrc { - fn set_uri(&mut self, uri_str: &Option) -> bool { + fn set_uri(&mut self, uri_str: &Option<&str>) -> bool { if self.response.is_some() { println_err!("Can't set URI after starting"); return false; @@ -135,7 +135,7 @@ impl Source for HttpSrc { return true; }, Some(ref uri_str) => { - let uri_parsed = Url::parse(uri_str.as_str()); + let uri_parsed = Url::parse(uri_str); match uri_parsed { Ok(u) => { if u.scheme() == "http" || diff --git a/src/rssink.rs b/src/rssink.rs index baacac69..a5516ad3 100644 --- a/src/rssink.rs +++ b/src/rssink.rs @@ -24,7 +24,7 @@ use std::ptr; use utils::*; pub trait Sink: Sync + Send { - fn set_uri(&mut self, uri_str: &Option) -> bool; + fn set_uri(&mut self, uri_str: &Option<&str>) -> bool; fn get_uri(&self) -> Option; fn start(&mut self) -> bool; fn stop(&mut self) -> bool; @@ -44,7 +44,7 @@ pub extern "C" fn sink_set_uri(ptr: *mut Box, uri_ptr: *const c_char) -> G GBoolean::from_bool(source.set_uri(&None)) } else { let uri = unsafe { CStr::from_ptr(uri_ptr) }; - GBoolean::from_bool(source.set_uri(&Some(String::from(uri.to_str().unwrap())))) + GBoolean::from_bool(source.set_uri(&Some(uri.to_str().unwrap()))) } } diff --git a/src/rssource.rs b/src/rssource.rs index 92870c97..6ecc02c1 100644 --- a/src/rssource.rs +++ b/src/rssource.rs @@ -23,7 +23,7 @@ use std::ptr; use utils::*; pub trait Source: Sync + Send { - fn set_uri(&mut self, uri_str: &Option) -> bool; + fn set_uri(&mut self, uri_str: &Option<&str>) -> bool; fn get_uri(&self) -> Option; fn is_seekable(&self) -> bool; fn get_size(&self) -> u64; @@ -48,7 +48,7 @@ pub extern "C" fn source_set_uri(ptr: *mut Box, uri_ptr: *const c_char) GBoolean::from_bool(source.set_uri(&None)) } else { let uri = unsafe { CStr::from_ptr(uri_ptr) }; - GBoolean::from_bool(source.set_uri(&Some(String::from(uri.to_str().unwrap())))) + GBoolean::from_bool(source.set_uri(&Some(uri.to_str().unwrap()))) } }