* minimized unsafe scope
* removed pub from `from_ptr` function
Signed-off-by: Zixing Liu <liushuyu(a)aosc.io>
---
src/stream.rs | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/stream.rs b/src/stream.rs
index 3a83b34..10145eb 100644
--- a/src/stream.rs
+++ b/src/stream.rs
@@ -114,17 +114,18 @@ impl Drop for Stream {
impl Stream {
pub fn new(conn: &Connect, flags: StreamFlags) -> Result<Stream, Error>
{
- unsafe {
- let ptr = virStreamNew(conn.as_ptr(), flags as libc::c_uint);
- if ptr.is_null() {
- return Err(Error::new());
- }
- return Ok(Stream::from_ptr(ptr));
+ let ptr = unsafe { virStreamNew(conn.as_ptr(), flags as libc::c_uint) };
+ if ptr.is_null() {
+ return Err(Error::new());
}
+ return Ok(Stream::from_ptr(ptr));
}
- pub fn from_ptr(ptr: sys::virStreamPtr) -> Stream {
- Stream { ptr: Some(ptr), callback: None }
+ fn from_ptr(ptr: sys::virStreamPtr) -> Stream {
+ Stream {
+ ptr: Some(ptr),
+ callback: None,
+ }
}
pub fn as_ptr(&self) -> sys::virStreamPtr {
@@ -136,9 +137,9 @@ impl Stream {
if virStreamFree(self.as_ptr()) == -1 {
return Err(Error::new());
}
- self.ptr = None;
- return Ok(());
}
+ self.ptr = None;
+ return Ok(());
}
pub fn finish(self) -> Result<(), Error> {
--
2.25.0