[libvirt] [rust PATCH v2 5/5] libvirt-rust: stream: addressed comments

Zixing Liu liushuyu at aosc.io
Tue Dec 24 07:12:55 UTC 2019


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

Signed-off-by: Zixing Liu <liushuyu at aosc.io>
---
 src/stream.rs | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/src/stream.rs b/src/stream.rs
index 0d84fd7..ea623f6 100644
--- a/src/stream.rs
+++ b/src/stream.rs
@@ -114,16 +114,14 @@ 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 {
+    fn from_ptr(ptr: sys::virStreamPtr) -> Stream {
         Stream {
             ptr: Some(ptr),
             callback: None,
@@ -139,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.24.1





More information about the libvir-list mailing list