Re: [PATCH v2 5/8] rust: debugfs: support blobs from smart pointers

Alexandre Courbot
2025-10-22T05:57:51Z

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>`?