[PATCH v22 2/5] rust: types: Add Ownable/Owned types

sashiko-bot at kernel.org sashiko-bot at kernel.org
Tue Nov 17 14:22:59 UTC 2026


> From: Asahi Lina <lina+kernel at asahilina.net>
> 
> By analogy to `AlwaysRefCounted` and `ARef`, an `Ownable` type is a
> (typically C FFI) type that *may* be owned by Rust, but need not be. Unlike
> an `ARef<T>`, an `Owned<T>` cannot be cloned. At most one `Owned<T>` exists
> for an object at any time, and the type `T` decides whether other
> references to the object may exist together with it.
> 
> Conceptually, this is similar to a `KBox<T>`, except that it delegates
> resource management to the `T` instead of using a generic allocator.
> 
> [ om:
>   - Split code into separate file and `pub use` it from types.rs.
>   - Make from_raw() and into_raw() public.
>   - Remove OwnableMut, and make DerefMut dependent on Unpin instead.
>   - Usage example/doctest for Ownable/Owned.
>   - Fixes to documentation and commit message.
> ]
> 
> Link: https://lore.kernel.org/all/20250202-rust-page-v1-1-e3170d7fe55e@asahilina.net/
> Signed-off-by: Asahi Lina <lina+kernel at asahilina.net>
> Co-developed-by: Oliver Mangold <oliver.mangold at pm.me>
> Signed-off-by: Oliver Mangold <oliver.mangold at pm.me>
> [ Andreas: Updated documentation, examples, and formatting. Change safety
>   requirements, safety comments. Let `T` decide whether other references
>   may exist together with an `Owned<T>`. ]
> Co-developed-by: Andreas Hindborg <a.hindborg at kernel.org>
> Signed-off-by: Andreas Hindborg <a.hindborg at kernel.org>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261116-unique-ref-v22-0-12029383206d@kernel.org?part=2




More information about the Linux-security-module-archive mailing list