qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: "Marc-André Lureau" <marcandre.lureau@gmail.com>
Cc: "P. Berrange, Daniel" <berrange@redhat.com>,
	"Sergio Lopez Pascual" <slp@redhat.com>,
	"Hajnoczi, Stefan" <stefanha@gmail.com>,
	qemu-devel <qemu-devel@nongnu.org>,
	"Armbruster, Markus" <armbru@redhat.com>,
	"Sebastian Dröge" <slomo@circular-chaos.org>,
	"John Snow" <jsnow@redhat.com>
Subject: Re: [PATCH] PoC: Rust binding for QAPI (qemu-ga only, for now)
Date: Wed, 30 Sep 2020 16:02:59 +0200	[thread overview]
Message-ID: <59a29e14-57d8-4246-14ce-375f6c9ce4dc@redhat.com> (raw)
In-Reply-To: <CAJ+F1CL7r31u1bQLRGmbZt-BPLM3XefFdY9O3Mk=VMmgJ76aiw@mail.gmail.com>

On 30/09/20 11:15, Marc-André Lureau wrote:
> Why BorrowedMutPointer provides both *const P and *mut P ? The *const P
> conversion seems overlapping with BorrowedPointer.

"&mut T" implements Borrow so it seemed obvious to have as_ptr in
BorrowedMutPointer too.  Though I certainly should implement Borrow in
BorrowedMutPointer.

>     > I don't have your head, so I find it hard to remember & work with.
>     It> uses all possible prefixes: with_, from_, as_, as_mut, to_, and
>     into_.
>     > That just blows my mind, sorry :)
> 
>     Ahah I don't have your head either!  The idea anyway is to reuse
>     prefixes that are common in Rust code:
> 
>     * with_: a constructor that uses something to build a type (think
>     Vec::with_capacity) and therefore takes ownership
> 
> ForeignConvert::with_foreign (const *P -> T) doesn't take ownership.
> 
> The Rust reference for this kind of conversion is CStr::from_ptr.

Ok, I'll take a look.

>     * as_: a cheap conversion to something, it's cheap because it reuses the
>     lifetime (and therefore takes no ownership).  Think Option::as_ref.
> 
> as_ shouldn't create any object, and is thus unsuitable for a general
> rs<->sys conversion function (any).

as_foreign function does not create anything, it reuses the storage to
provide a pointer.  It seems similar to as_slice for example.

>     * from_/to_: a copying and possibly expensive conversion (that you have
>     to write the code for).  Because it's copying, it doesn't consume the
>     argument (for from_) or self (for to_).
> 
> and that's what glib-rs uses (and CStr).

Sort of, I found the none/full suffixes not really idiomatic for Rust.

>     * into_: a conversion that consumes the receiver
> 
> That's not used by glib afaik, but we should be able to introduce it for
> "mut *P -> T", it's not incompatible with FromPtrFull::from_full.

Right.  It's just a different way to write the same thing.  Usually it
is a bit more concise because it allows more type inference.

>     > Then, I don't understand why ForeignConvert should hold both the
>     > "const *P -> T" and "&T -> const *P" conversions. Except the
>     > common types, what's the relation between the two?
> 
>     Maybe I'm wrong, but why would you need just one?
> 
> No I mean they could be on different traits. One could be implemented
> without the other. Or else I don't understand why the other conversion
> functions would not be in that trait too.

The other conversion functions require taking ownership, and I was not
sure if it would always be possible to do so.  For no-ownership-taken
conversions, however, it seemed to me that you'd rarely be unable to
implement one of the two directions.  I might be wrong.

In general though I agree that the changes are mostly cosmetic.

Paolo



  reply	other threads:[~2020-09-30 14:05 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-10 17:48 [PATCH] PoC: Rust binding for QAPI (qemu-ga only, for now) marcandre.lureau
2020-09-11 10:24 ` Paolo Bonzini
2020-09-11 13:08   ` Paolo Bonzini
2020-09-11 14:00     ` Marc-André Lureau
2020-09-11 15:17       ` Paolo Bonzini
2020-09-29 17:55         ` Marc-André Lureau
2020-09-29 18:23           ` Paolo Bonzini
2020-09-30  9:15             ` Marc-André Lureau
2020-09-30 14:02               ` Paolo Bonzini [this message]
2020-09-11 10:46 ` Daniel P. Berrangé
2020-09-11 11:03   ` Marc-André Lureau
2020-09-11 11:28   ` Paolo Bonzini
2020-09-11 11:31     ` Daniel P. Berrangé
2020-09-11 14:19     ` John Snow
2020-09-11 14:17 ` Marc-André Lureau
2020-09-21  9:16 ` Markus Armbruster
2020-09-21  9:30   ` Paolo Bonzini
2020-09-22 14:59     ` Markus Armbruster
2020-09-21 10:04   ` Marc-André Lureau
2020-09-22 15:09     ` Markus Armbruster
2020-09-22 16:35       ` Marc-André Lureau
2020-09-22 17:08         ` Paolo Bonzini
2020-09-29  7:45           ` Marc-André Lureau
2020-09-29 10:14             ` Paolo Bonzini
2020-09-29 10:34               ` Marc-André Lureau
2020-09-29 11:00                 ` Paolo Bonzini
2020-09-29 11:34                   ` Marc-André Lureau
2020-09-30  7:34                     ` Markus Armbruster
2020-09-30  7:51                       ` Marc-André Lureau
2020-09-30 13:14                         ` Paolo Bonzini
2020-09-22 16:52       ` Daniel P. Berrangé
2020-09-23 11:51         ` Markus Armbruster
2020-09-21 10:11   ` Marc-André Lureau
2020-09-22 15:37     ` Markus Armbruster
2020-09-22 16:25       ` Marc-André Lureau
2020-09-24  7:31         ` Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=59a29e14-57d8-4246-14ce-375f6c9ce4dc@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=marcandre.lureau@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=slomo@circular-chaos.org \
    --cc=slp@redhat.com \
    --cc=stefanha@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).