On Tue, Aug 12, 2025 at 09:23:59PM +0200, Paolo Bonzini wrote: > Date: Tue, 12 Aug 2025 21:23:59 +0200 > From: Paolo Bonzini <pbonz...@redhat.com> > Subject: Re: [RFC 16/26] memory: Make flatview_do_translate() return a > pointer to MemoryRegionSection > > Il mar 12 ago 2025, 17:17 Zhao Liu <zhao1....@intel.com> ha scritto: > > > But look closer to Opaque<>, it has 2 safe methods: as_mut_ptr() & > > raw_get(). > > > > These 2 methods indicate that the T pointed by Qpaque<T> is mutable, > > which has the conflict with the original `*const > > bindings::MemoryRegionSection`. > > > > So from this point, it seems unsafe to use Qpaque<> on this case. > > > > Yes, it's similar to NonNull<>. I am not sure that you need Opaque<> here; > since the pointer is const, maybe you can just dereference it to a > &bindings::MemoryRegionSection. Is it useful to have the Opaque<> wrapper > here?
I agree. Opaque<> is not necessary here. We can have a simple wrapper: pub struct MemoryRegionSection(*const bindings::MemoryRegionSection) or pub struct MemoryRegionSection(NonNull<bindings::MemoryRegionSection>) with immutable only use. In future, if there're more similar case, then we can have a OpaqueRef<> like Manos suggested. Thanks, Zhao