Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp4888792rwb; Sun, 4 Dec 2022 09:59:27 -0800 (PST) X-Google-Smtp-Source: AA0mqf7B8G7p8cQlED5aH0cshDgdS71x2ROuGu8KQMr+vaTV+dI+mjK4VZMut4xJMG68LvR+2ZGL X-Received: by 2002:a17:906:124d:b0:7ad:b822:d2e4 with SMTP id u13-20020a170906124d00b007adb822d2e4mr66958504eja.35.1670176767802; Sun, 04 Dec 2022 09:59:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670176767; cv=none; d=google.com; s=arc-20160816; b=y0ejAlC2BD5y7EkTs5jvwbFbU9XWmZJy2q9c14WHnp7q38ujwghoZO7fe7AJayNMDq Ww46rId8Fgu9+4udNVPQBMdLcK4iOEWMhA0ISKJtbVShEb32Rg7VNyi+dd6dU6QKOS9k ZORdOuV0WZbSRsHhWLP/0nDA/CMTxGI+0m2J0pwEvxp+1frcdR7067LOPtX4IBlqW/Ok DB2RMd4C/+mi9QuzBAIujAXmHjNlAiM99VQfQKynwSdcNRbgBIBiwAKROvhCeTpduxYJ vkThgH5eyQGyr4SqKXQX7PDuupYMrNI3t7ASYYj6rWYyKVWDvhcQuhPJQvsWdDgC1iK/ QLKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=TXEZvr3bKu2vBIW+lpuSVItbWZwpWlZ50nx9XuTinWU=; b=WAiDzkVXkdsWfsGEM2O3KLQLZscXKV+VzE4SOmjM7wsTH+R64joDMKb2lBmRrP3MOG 8pbYte1zJsP7KnFuvycHdDSMTwJnTdUHu+bBk5G75BNNHJlEnKS8U8RwXB6Iv+nRhJcl phXOCorACwKbLw4hsuDY1IRl6LpidOPl/zdkFC9OyoIBppTfRvCIo7NDFmHZ2meGVT4d dqMtGkuDDVMVoHONnDtrURwXYyjUXFD3FgbOzJtLa2d+GrqkmIJRvRvCgBwSn2n7zlFN 9jniEkMXLr36neqD8quX35qKbibnu4x0S4rCbIsKwHOl1sz2//uL1Lrrzbez6qGGV3YB UJcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=K5E0+LOn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y7-20020a056402358700b0046ba0b85e8asi10729809edc.624.2022.12.04.09.59.08; Sun, 04 Dec 2022 09:59:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=K5E0+LOn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230266AbiLDRgX (ORCPT + 82 others); Sun, 4 Dec 2022 12:36:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229938AbiLDRgV (ORCPT ); Sun, 4 Dec 2022 12:36:21 -0500 Received: from mail-oa1-x2c.google.com (mail-oa1-x2c.google.com [IPv6:2001:4860:4864:20::2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F43E14096; Sun, 4 Dec 2022 09:36:20 -0800 (PST) Received: by mail-oa1-x2c.google.com with SMTP id 586e51a60fabf-14455716674so4867806fac.7; Sun, 04 Dec 2022 09:36:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=TXEZvr3bKu2vBIW+lpuSVItbWZwpWlZ50nx9XuTinWU=; b=K5E0+LOnggn/gYMPFlw4zI4PSzD+JHSdGy4UU6wttfDL2DlzF3ueIgIOWR7oRXgHct xh9/3Brq5EmMilnZRjlVNdphsZo4PWHbyyb/k6XiLdDRWtE6JynFvaohTeAc9fSEii3/ O/cJm1NIlZq/KdCpD/QjSgbxheAoTFj8fsV9nL/J0zC0HAwKKezkr0ZseQAaU0n9/BBJ xMdieALMDasrbQlarT2uBdq5jLLcve65SIkefFLHCVyhwxyGzH4ePF+6ikpWycWuWATh XP5BoyplLSdQ/zWMjnzqnSv5Vl3OeM3M9Lsn+L0yP14j8Ftd9RDrKoOmoHz0LwrkqcoQ AIDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=TXEZvr3bKu2vBIW+lpuSVItbWZwpWlZ50nx9XuTinWU=; b=Ibq8XhiRu4yKwKUoleDS78llmAwgua7rD4Nl1ozubPkoPjo9soYavhRgH17R+xQlkt 16NCGui+TCZAplJ9d8z77bPe+3vZZ02ivcwm0sDUqOsrQvUAAy/xGFtlr+kdRgOnpOoj 5DMTz70rH6QrTQ1Wq9reXE8miYzo6klMWCb5K0LaNc7ffeHtcZfsZ0PKyqDAhV52IRuj dOeCmOStUW9dCf4jNJ+IJjM2wBXTOUPIi/C/LRDPr6jGInTsyJyKcorKonhWyrAD9V0u EwTgtPP+7sYvm7U1zU5j2C8ukyfPTefVB03axP9Z69In1jBf3OrTE/4pdTT72qU4oN5M K8Aw== X-Gm-Message-State: ANoB5pk7R6IKjsq+JgJMU/F3wZtFTv7VE0hpRrHElvt62x3JnMpDAvBp sdnjBGwokH2UsnEgPpQluUH+C1f/7Tv78YcG/NI= X-Received: by 2002:a05:6870:6c02:b0:143:80af:e36a with SMTP id na2-20020a0568706c0200b0014380afe36amr22895324oab.254.1670175379350; Sun, 04 Dec 2022 09:36:19 -0800 (PST) MIME-Version: 1.0 References: <20221202161502.385525-1-ojeda@kernel.org> <20221202161502.385525-28-ojeda@kernel.org> <20221204103153.117675b1@GaryWorkstation> In-Reply-To: <20221204103153.117675b1@GaryWorkstation> From: Wedson Almeida Filho Date: Sun, 4 Dec 2022 17:36:08 +0000 Message-ID: Subject: Re: [PATCH v2 27/28] rust: types: add `Either` type To: Gary Guo Cc: Josh Triplett , ojeda@kernel.org, Alex Gaynor , Boqun Feng , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Wei Liu Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 4 Dec 2022 at 10:31, Gary Guo wrote: > > On Fri, 2 Dec 2022 15:41:59 -0800 > Josh Triplett wrote: > > > On Fri, Dec 02, 2022 at 05:14:58PM +0100, ojeda@kernel.org wrote: > > > From: Wedson Almeida Filho > > > > > > Introduce the new `types` module of the `kernel` crate with > > > `Either` as its first type. > > > > > > `Either` is a sum type that always holds either a value > > > of type `L` (`Left` variant) or `R` (`Right` variant). > > > > > > For instance: > > > > > > struct Executor { > > > queue: Either, > > > } > > > > This specific example seems like it would be better served by the > > existing `Cow` type. > > We use `no_global_oom_handling`, which gates most `ToOwned` > implementations (e.g. `str` cannot implement `to_owned()` because it > cannot guarantee allocation success). > > So the Rust `Cow` is pretty much useless in the kernel. It's also implemented in `std`, which the kernel doesn't include. (Which is actually good for us, since we can't really use it.) Josh, how do you feel about adding a `TryToOwned` trait to `core::borrow`? This would be similar to the precedent of `TryFrom` in addition to `From` for the fallible case, and would be usable by the kernel.