[libvirt-rust PATCH v3 4/4] libvirt-rust: stream: addressed comments

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



* minimized unsafe scope
* removed pub from `from_ptr` function

Signed-off-by: Zixing Liu <liushuyu@xxxxxxx>
---
 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






[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux