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

Hiroyuki Katsura hiroyuki.katsura.0513 at gmail.com
Mon Aug 5 13:43:14 UTC 2019


> My initial idea was to split the Handle -> Handle<'a> change in an own
> patch, to make it easier to review; unfortunately

Oh, I misunderstood what you meant. It is easy to use PhantomData.
Should I fix to use it? Or, it's ok to just mention the reason?

Note: the reason why Handle -> Handle<'a> is that without clarifying it,
rust compiler cannot infer how long the trait object of callbacks will
live.
And then, it is considered as 'static lifetime. It is not useful for users,
I think.

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

Yes. To my knowledge, it is available from Rust 2018.

> Remember the copyright/license in new files.

I forgot adding a license to the divided patch... I'll fix it if the patch
should be divided into two parts.

Regards,
Hiroyuki


2019年8月5日(月) 21:01 Pino Toscano <ptoscano at redhat.com>:

> 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 --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20190805/a7b63a6a/attachment.htm>


More information about the Libguestfs mailing list