[libvirt] [rust PATCH v2 5/5] libvirt-rust: stream: addressed comments
Sahid Orentino Ferdjaoui
sahid.ferdjaoui at canonical.com
Fri Jan 10 11:49:45 UTC 2020
On Tue, Dec 24, 2019 at 12:12:55AM -0700, Zixing Liu wrote:
> * 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(-)
Reviewed-by: Sahid Orentino Ferdjaoui <sahud.ferdjaoui at canonical.com>
> 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