From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 068FA223DE7; Tue, 8 Jul 2025 15:00:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751986809; cv=none; b=f0Z8ZO6nj4KnQYpuPl7PlpwMNfzX/kwZNd6ik4M+dBNHYyDxdmjUM+A/yL6wCrI8qOWmc9U/KuosUlkG9cMcIOnhHgBUOXVHx4ZVNcRpkPMJTp/JZ8EvEru+usEzdQto8fRXpmCj+FFY93VRcIuhpwMX7aLicaasRobdZqe9rHc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751986809; c=relaxed/simple; bh=8zhdXKTkB9Q4veJXhlqQ8WPtuFRRjdAu8mZrNb0FZIM=; h=Mime-Version:Content-Type:Date:Message-Id:Cc:Subject:From:To: References:In-Reply-To; b=hCOTakkvcZLjl3/gepX3W8GFzLoDxUHnUj0xZxPDg2HrlA6qP+v8oEIUwoDNYZ8hk97kQTMP+jsS8GCQAvqIJGDuDslN3kl19gHLSG70xQ8p5NsDQJpPYO4IpkDBiQpnzBCLTbBfbHkwP5RzWtOHG6N3mhdAes7qd6AtzyiGhDY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ABGeFg8I; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ABGeFg8I" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5426FC4CEEF; Tue, 8 Jul 2025 15:00:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751986808; bh=8zhdXKTkB9Q4veJXhlqQ8WPtuFRRjdAu8mZrNb0FZIM=; h=Date:Cc:Subject:From:To:References:In-Reply-To:From; b=ABGeFg8IZcrpiwF2E5/VAvkRG+wMvkvFc2Ddba5FN/gXW/iwOBuVdp6OTkqN3dwjO uWSDMs9o0RbluEucdgQi/Qg334hI4dOlr/+eey3nPQIUywQ6Vohzx+oq1rxszOMGNx Tn3aQJKZgoy4dR8u8wF5I496GfCTu/vDtiV+FO67BgKVOLhAV3+OCqb4PecIQg3wEJ S8+ZIqWxLo1ycJ6NveVnpztGPoihkyS3QRPYpxXaUwLhjUYpj7vgSuZBxi1uAEkAVo UpK3bLYur6v0I/qfPkVlZsxRNSyg32bvDeg2vZrLJLiGQldfK2aeW5xHv13HuX+n2+ ECB60jByno6Zw== Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Tue, 08 Jul 2025 17:00:03 +0200 Message-Id: Cc: "Miguel Ojeda" , "Alex Gaynor" , "Boqun Feng" , "Gary Guo" , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , "Andreas Hindborg" , "Alice Ryhl" , "Trevor Gross" , "Asahi Lina" , , Subject: Re: [PATCH v11 1/4] rust: types: Add Ownable/Owned types From: "Benno Lossin" To: "Oliver Mangold" X-Mailer: aerc 0.20.1 References: <20250618-unique-ref-v11-0-49eadcdc0aa6@pm.me> <20250618-unique-ref-v11-1-49eadcdc0aa6@pm.me> In-Reply-To: On Tue Jul 8, 2025 at 11:56 AM CEST, Oliver Mangold wrote: > On 250707 1123, Benno Lossin wrote: >> On Mon Jul 7, 2025 at 8:58 AM CEST, Oliver Mangold wrote: >> > On 250702 1303, Benno Lossin wrote: >> >> On Wed Jun 18, 2025 at 2:27 PM CEST, Oliver Mangold wrote: >> >> > +/// >> >> > +/// # Invariants >> >> > +/// >> >> > +/// The pointer stored in `ptr` can be considered owned by the [`O= wned`] instance. >> >> >> >> What exactly is "owned" supposed to mean? It depends on the concrete = `T` >> >> and that isn't well-defined (since it's a generic)... >> > >> > "owned" means that access to the `T` is exclusive through the `Owned`, >> > so normal Rust semantics can be applied. >>=20 >> Okay, in that case just say that `ptr` has exclusive access. > > Or, ehm, sorry, I forgot, ownership also implies that the allocation of t= he > underlying resource/object is now under the responsibility of the owner, > i.e. the owner should free it at the appropriate time. > > In short, just the standard meaning of ownership in Rust. > > https://doc.rust-lang.org/book/ch04-01-what-is-ownership.html Okay that's good to hear. I think what tripped me up the most was the "can be considered" wording. Let's just say: /// # Invariants /// /// - `ptr` is valid, /// - `*ptr` is owned by `self`, /// - `ptr` is an "owning pointer" according to the [`Ownable`] impleme= ntation for `T`. And then on `Ownable` we add: /// # Invariants /// /// An implementer of this trait needs to define which pointers can be = supplied to /// [`Self::release`]. These pointers are called "owning pointers". This should be as general as possible and still give us exactly the guarantees that we need to implement `Owned`. `Owned::from_raw` can then require that the pointer is an owning pointer (& it's valid) and that the caller yields ownership to `from_raw`. --- Cheers, Benno