[Libguestfs] [PATCH 1/2] Rust bindings: Add Event structs, Clarify Handle lifetime

Pino Toscano ptoscano at redhat.com
Mon Aug 5 12:01:39 UTC 2019


On Monday, 5 August 2019 08:59:31 CEST Hiroyuki Katsura wrote:
> Without clarifying handle's lifetime, it is unable
> to see how long the callbacks which the handle
> owns will live. Then, Rust compiler will infer
> that the callbacks have 'static lifetime. It is
> not convenient for users.
> ---

My initial idea was to split the Handle -> Handle<'a> change in an own
patch, to make it easier to review; unfortunately, doing this hits
error E0392:
https://doc.rust-lang.org/error-index.html#E0392
So either this change goes together with other changes (like in this
patch), or it uses PhantomData just to remove it after adding the
callbacks. :-/

I guess we can keep this patch as it is; please describe a bit more the
addition of events, mentioning the Handle<'a> change is needed because
<insert here what you already wrote as commit message>.

> diff --git a/rust/src/base.rs b/rust/src/base.rs
> index 02ad33535..c17607cb3 100644
> --- a/rust/src/base.rs
> +++ b/rust/src/base.rs
> @@ -17,6 +17,9 @@
>   */
>  
>  use crate::error;
> +use crate::event;
> +use crate::guestfs;

guestfs.rs has:
use crate::base::*;

So it means rust allows cyclic uses of modules/crates?

> diff --git a/rust/src/event.rs b/rust/src/event.rs
> new file mode 100644
> index 000000000..c363e913a
> --- /dev/null
> +++ b/rust/src/event.rs
> @@ -0,0 +1,4 @@
> +#[derive(Hash, PartialEq, Eq)]
> +pub struct EventHandle {
> +    eh: i32,
> +}

Remember the copyright/license in new files.

-- 
Pino Toscano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part.
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20190805/3422b1d5/attachment.sig>


More information about the Libguestfs mailing list