Re: [PATCH v6 3/5] rust: debugfs: Support arbitrary owned backing for File

From: Matthew Maurer
Date: Wed Jun 18 2025 - 11:02:37 EST


> We may want to consider using the ForeignOwnable trait here instead. The

I was considering trying to switch over to `StableDeref`-like trait
[1] in a follow-up patchset. The core property I need is that moving
the `D` cannot result in the pointer it would `deref` to changing.

The problem with `ForeignOwnable` is that it forbids the user from
passing in a `Box<dyn Foo>`, because that doesn't fit in a `void*` A
`StableDeref` version would not have this issue. I agree that
`ForeignOwnable` would be a strict upgrade to what I have now, since a
user can still pass in a `Box<Box<dyn Foo>>` and have it work with
`ForeignOwnable`, and if we ever added `StableDeref`, then
`ForeignOwnable` would have a blanket impl for it.

I'll send a new version using `ForeignOwnable`, and we can consider
the `StableDeref` version in the future.

[1]: https://docs.rs/gimli/latest/gimli/trait.StableDeref.html


> trait is implemented by anything that can be converted to/from a void
> pointer, so you can:
>
> * When creating the file, convert it to a void pointer that you store in
> File and pass to debugfs_create_file_full.
> * When displaying the file, create a borrowed version of the void
> pointer and display that.
> * When freeing the File, convert the void pointer back into an owned
> value and drop it.
>
> For cases where a box really is necessary, the user can create a box and
> pass it themselves. But if the user already has a pointer type (e.g. and
> Arc<T> or &'static T) then they can pass that pointer directly and the
> pointer is stored as a void pointer without the Box indirection.
>
> Alice