From: Paolo Bonzini <pbonzini@redhat.com>
To: "Marc-André Lureau" <marcandre.lureau@gmail.com>,
"Sebastian Dröge" <slomo@circular-chaos.org>
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>,
John Snow <jsnow@redhat.com>
Subject: Re: [PATCH] PoC: Rust binding for QAPI (qemu-ga only, for now)
Date: Tue, 29 Sep 2020 20:23:36 +0200 [thread overview]
Message-ID: <ddd2e282-3e0e-1c0e-2af3-7ca59c322ef9@redhat.com> (raw)
In-Reply-To: <CAJ+F1CL1kzvHRmMOTq38r0PNyCJhzyqWeiNb71e7sabaWOwdsQ@mail.gmail.com>
On 29/09/20 19:55, Marc-André Lureau wrote:
> My understanding of what you propose is:
> - ForeignConvert::with_foreign
> - FromForeign::from_foreign (with implied into_native)
> And:
> - ForeignConvert::as_foreign (with the BorrowedPointer/stash-like)
> - ToForeign::to_foreign + ForeignConvert::as_foreign_mut (which seems
> wrongly designed in your proposal and unnecessary for now)
Might well be, but how is it wrong? (I'd like to improve).
> 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
* as_: a cheap conversion to something, it's cheap because it reuses the
lifetime (and therefore takes no ownership). Think Option::as_ref.
* 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_).
* into_: a conversion that consumes the receiver
It may well be over the top.
> 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?
> Finally, I thought you introduced some differences with the stash
> design, but in fact I can see that ForeignConvert::Storage works just
> the way as ToPtr::Storage. So composition should be similar. Only your
> example code is more repetitive as it doesn't indirectly refer to the
> trait Storage the same way as glib-rs does (via <T as ToPtr>::Storage).
Yes, that's the main difference. I removed Storage because I didn't
want to force any trait on BorrowedPointer's second type argument. It
seemed like a generic concept to me.
The other difference is that Stash is a tuple while BorrowedPointer is a
struct and has methods to access it. Stash seems very ugly to use.
> I am not making any conclusions yet, but I am not exactly happily going
> to switch to your proposal yet :)
Sure, no problem.
Paolo
next prev parent reply other threads:[~2020-09-29 18:26 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 [this message]
2020-09-30 9:15 ` Marc-André Lureau
2020-09-30 14:02 ` Paolo Bonzini
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=ddd2e282-3e0e-1c0e-2af3-7ca59c322ef9@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).