From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 60E8DFF8867 for ; Mon, 27 Apr 2026 22:16:30 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C959510E153; Mon, 27 Apr 2026 22:16:29 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="gCSOdWN5"; dkim-atps=neutral Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by gabe.freedesktop.org (Postfix) with ESMTPS id B50DD10E153 for ; Mon, 27 Apr 2026 22:16:28 +0000 (UTC) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id 1472D60121; Mon, 27 Apr 2026 22:16:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3EAAFC19425; Mon, 27 Apr 2026 22:16:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777328187; bh=PGxVViMhHB03sAijAlxNGF7mgYEJwbY2rwD26gbYrHs=; h=Date:To:From:Subject:Cc:References:In-Reply-To:From; b=gCSOdWN5D78SXVP+wRiSah70WX8vRhFWzTMxldjJDoEzDh6ADKZ+QjTRz0r2SqQ5W jsnRgoXUP5yPTSYZ/Dv68rQFrSs/MnSnT7/KCoxEiJZe0882jXgk2PPazeiNotutr9 CGFSPYFy3CIZf7rdd0Xky9gMP+hXeMZtsd2CPmIvGyVi6JJV6AO/IPHpFvXsagP9za AbTQbRn0Wn7ykefDrvhM3Rqlvl/Bb/uMpFVzoyYbXCtnA/FzlV5XljmA88Wr1ORiRq ORqJK2J+jrYSlZFhzq4oLqrwuQh5tUOWOiMJTxC4U774y57AvoJEzxd0ThPOzhGvWt ZBbqvlZ6TwevQ== Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Tue, 28 Apr 2026 00:16:20 +0200 Message-Id: To: , , , , , , , , , , , , , , , , , , , , , From: "Danilo Krummrich" Subject: Re: [PATCH 02/24] rust: types: add `ForLt` trait for higher-ranked lifetime support Cc: , , , , , , , References: <20260427221155.2144848-1-dakr@kernel.org> <20260427221155.2144848-3-dakr@kernel.org> In-Reply-To: <20260427221155.2144848-3-dakr@kernel.org> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Tue Apr 28, 2026 at 12:11 AM CEST, Danilo Krummrich wrote: > From: Gary Guo > > There are a few cases, e.g. when dealing with data referencing each other= , > one might want to write code that are generic over lifetimes. For example= , > if you want take a function that takes `&'a Foo` and gives `Bar<'a>`, you > can write: > > f: impl for<'a> FnOnce(&'a Foo) -> Bar<'a>, > > However, it becomes tricky when you want that function to not have a fixe= d > `Bar`, but have it be generic again. In this case, one needs something th= at > is generic over types that are themselves generic over lifetimes. > > `ForLt` provides such support. It provides a trait `ForLt` which describe= s > a type generic over lifetime. One may use `ForLt::Of<'a>` to get an > instance of a type for a specific lifetime. > > For the case of cross referencing, one would almost always want the > lifetime to be covariant. Therefore this is also made a requirement for t= he > `ForLt` trait, so functions with `ForLt` trait bound can assume covarianc= e. > > A macro `ForLt!()` is provided to be able to obtain a type that implement= s > `ForLt`. For example, `ForLt!(for<'a> Bar<'a>)` would yield a type that > `::Of<'a>` is `Bar<'a>`. This also works with lifetime > elision, e.g. `ForLt!(Bar<'_>)` or for types without lifetime at all, e.g= . > `ForLt!(u32)`. > > The API design draws inspiration from the higher-kinded-types [1] crate, > however different design decision has been taken (e.g. covariance > requirement) and the implementation is independent. > > License headers use "Apache-2.0 OR MIT" because I anticipate this to be > used in pin-init crate too which is licensed as such. > > Link: https://docs.rs/higher-kinded-types/ [1] > > Signed-off-by: Gary Guo Signed-off-by: Danilo Krummrich