From: Zhao Liu <zhao1.liu@intel.com>
To: Peter Maydell <peter.maydell@linaro.org>,
Junjie Mao <junjie.mao@hotmail.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
"Daniel P. Berrange" <berrange@redhat.com>,
Eduardo Habkost <eduardo@habkost.net>,
qemu-devel@nongnu.org
Subject: Re: [Question] What is the definition of “private” fields in QOM?
Date: Tue, 22 Oct 2024 23:09:17 +0800 [thread overview]
Message-ID: <ZxfAHeFz0+ZU4SA/@intel.com> (raw)
In-Reply-To: <CAFEAcA9m=zy3MMcE+tZwpms36BUx+DsGvt7h1jSuqidFOx0aeA@mail.gmail.com>
On Tue, Oct 22, 2024 at 09:42:03AM +0100, Peter Maydell wrote:
> Date: Tue, 22 Oct 2024 09:42:03 +0100
> From: Peter Maydell <peter.maydell@linaro.org>
> Subject: Re: [Question] What is the definition of “private” fields in
> QOM?
>
> On Tue, 22 Oct 2024 at 04:24, Junjie Mao <junjie.mao@hotmail.com> wrote:
> > Peter Maydell <peter.maydell@linaro.org> writes:
> > > For Rust we get to make a fresh start on these things. If
> > > we do mark all these fields not public, what would break?
> > >
> >
> > The only thing that breaks today is std::mem::offset_of! which respects
> > field visibility. Defining a Property const structure requires getting
> > the field offset outside of the state context.
> >
> > To me properties are still private to the device state and must be
> > accessed via their getters & setters. A solution to that is to keep
> > properties private but make their offsets public in our alternative to
> > offset_of!.
>
> Yes, conceptually I agree that the fields underlying a
> property are private and the public interface is the
> prop get/set API. (In C the prop/get set can if it
> likes do things like enforcing value limits, so looking
> directly at the underlying field would bypass that.)
>
> At any rate it sounds like it would be a good idea to
> at least mark as not-public all the fields we can do that
> way, and have a comment
> /* pub only because they are properties */
> for the fields used by the Property structs, even if we
> don't yet have a better way to deal with the latter.
Thank you both, Peter and Junjie!! I understand that the benefit of
declaring private states/classes in Rust is to avoid unnecessary
dependencies between different module/crates and to better manage
interactions between them. I'll go ahead and try out the methods you
both mentioned to compare them.
Regards,
Zhao
next prev parent reply other threads:[~2024-10-22 14:53 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-19 16:10 [Question] What is the definition of “private” fields in QOM? Zhao Liu
2024-10-21 8:35 ` Daniel P. Berrangé
2024-10-21 9:22 ` Zhao Liu
2024-10-21 9:25 ` Peter Maydell
2024-10-21 14:22 ` Zhao Liu
2024-10-21 14:20 ` Peter Maydell
2024-10-21 15:18 ` Zhao Liu
2024-10-21 15:06 ` Peter Maydell
2024-10-21 15:41 ` Zhao Liu
2024-10-21 16:47 ` Peter Maydell
2024-10-22 3:08 ` Junjie Mao
2024-10-22 8:42 ` Peter Maydell
2024-10-22 15:09 ` Zhao Liu [this message]
2024-10-22 15:01 ` Zhao Liu
2024-10-21 18:46 ` BALATON Zoltan
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=ZxfAHeFz0+ZU4SA/@intel.com \
--to=zhao1.liu@intel.com \
--cc=berrange@redhat.com \
--cc=eduardo@habkost.net \
--cc=junjie.mao@hotmail.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/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).