[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <DDOMC4F138FF.30W347U04XWZ8@nvidia.com>
Date: Wed, 22 Oct 2025 14:57:43 +0900
From: "Alexandre Courbot" <acourbot@...dia.com>
To: "Danilo Krummrich" <dakr@...nel.org>, <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>
Cc: <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 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?
> 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>`?
Powered by blists - more mailing lists