[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <deb9881f-5ef2-4e6a-a63d-56695c822f80@kernel.org>
Date: Wed, 22 Oct 2025 11:34:23 +0200
From: Danilo Krummrich <dakr@...nel.org>
To: Alexandre Courbot <acourbot@...dia.com>
Cc: gregkh@...uxfoundation.org, rafael@...nel.org, ojeda@...nel.org,
alex.gaynor@...il.com, boqun.feng@...il.com, gary@...yguo.net,
bjorn3_gh@...tonmail.com, lossin@...nel.org, a.hindborg@...nel.org,
aliceryhl@...gle.com, tmgross@...ch.edu, mmaurer@...gle.com,
rust-for-linux@...r.kernel.org, linux-fsdevel@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 5/8] rust: debugfs: support blobs from smart pointers
On 10/22/25 7:57 AM, Alexandre Courbot wrote:
> On Tue Oct 21, 2025 at 7:26 AM JST, Danilo Krummrich wrote:
> <snip>
>> @@ -51,12 +54,14 @@ pub trait BinaryWriter {
>> fn write_to_slice(&self, writer: &mut UserSliceWriter, offset: file::Offset) -> Result<usize>;
>> }
>>
>> +// Base implementation for any `T: AsBytes`.
>> impl<T: AsBytes> BinaryWriter for T {
>> fn write_to_slice(&self, writer: &mut UserSliceWriter, offset: file::Offset) -> Result<usize> {
>> writer.write_slice_partial(self.as_bytes(), offset)
>> }
>> }
>>
>> +// Delegate for `Mutex<T>`: Support a `T` with an outer mutex.
>
> I guess these two comments belong in the previous patch?
I added them in this patch since it is where the comments become useful, but
technically they can indeed go in the previous one.
>> impl<T: BinaryWriter> BinaryWriter for Mutex<T> {
>> fn write_to_slice(&self, writer: &mut UserSliceWriter, offset: file::Offset) -> Result<usize> {
>> let guard = self.lock();
>> @@ -65,6 +70,56 @@ fn write_to_slice(&self, writer: &mut UserSliceWriter, offset: file::Offset) ->
>> }
>> }
>>
>> +// Delegate for `Box<T, A>`: Support a `Box<T, A>` with no lock or an inner lock.
>> +impl<T, A> BinaryWriter for Box<T, A>
>> +where
>> + T: BinaryWriter,
>> + A: Allocator,
>> +{
>> + fn write_to_slice(&self, writer: &mut UserSliceWriter, offset: file::Offset) -> Result<usize> {
>> + self.deref().write_to_slice(writer, offset)
>> + }
>> +}
>> +
>> +// Delegate for `Pin<Box<T, A>>`: Support a `Pin<Box<T, A>>` with no lock or an inner lock.
>> +impl<T, A> BinaryWriter for Pin<Box<T, A>>
>> +where
>> + T: BinaryWriter,
>> + A: Allocator,
>> +{
>> + fn write_to_slice(&self, writer: &mut UserSliceWriter, offset: file::Offset) -> Result<usize> {
>> + self.deref().write_to_slice(writer, offset)
>> + }
>> +}
>> +
>> +// Delegate for `Arc<T>`: Support a `Arc<T>` with no lock or an inner lock.
>> +impl<T> BinaryWriter for Arc<T>
>> +where
>> + T: BinaryWriter,
>> +{
>> + fn write_to_slice(&self, writer: &mut UserSliceWriter, offset: file::Offset) -> Result<usize> {
>> + self.deref().write_to_slice(writer, offset)
>> + }
>> +}
>
> These 3 implementations are identical - can we replace some/all with
> just an implementation for anything implementing `Deref<T>`?
Unfortunately, this would lead to some ambiguity for the compiler. A type could
match
impl<T: AsBytes> BinaryWriter for T {}
and
impl<T, D> BinaryWriter for T
where
T: Deref<Target = D>,
D: BinaryWriter,
{}
at the same time.
Powered by blists - more mailing lists