Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2410979rwb; Fri, 2 Dec 2022 09:22:36 -0800 (PST) X-Google-Smtp-Source: AA0mqf7ww+ajbY+xuH9yY+/X8KL226ZotFVYJEbwQghek8+NOGnUYaMINFfbtJLI/7LCcPEaDoxA X-Received: by 2002:a17:907:3117:b0:7ae:6746:f26b with SMTP id wl23-20020a170907311700b007ae6746f26bmr60770241ejb.171.1670001756125; Fri, 02 Dec 2022 09:22:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670001756; cv=none; d=google.com; s=arc-20160816; b=loRNaz4Q66Gd/++9LTjtaNAUuu7T/ZdnB0HoKsZDq89Z9pKKd+DVoIncZhIRgE0CnP lBs0GP/DkBmHAQpuqhQLJcxgohuIMYnd0ZLDGv2s6bi9lqmgpH1hXKkhmf3zU1XDmCuZ O09IKjQxkQYVPHQ5Xb9xOUeYB60iry6m1FwC5PwN24ujF2mBTx3huv/n5S/sFQEGNLB2 HnAqoNSCMzxOB8z/64wjLMMdN2Asxf4ENkV48BRxWhJtQil3MMGP5toWmE0vbqnXxPqB DNj+5NkcAX7Sy2ZIQ+sEEz/TVVsXQvRW4gtf57KvcNwhQkNYoCH24NQ8tLdXinV+CalL 2U9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=H+qIDzozhgpQC8XQ4TzwJGrLT45xetRrm2RvjeIc7OA=; b=x10okwMcrXSdCUQB6QZKI0THpbLVvP8C2iX13H9wpN2bAzAkghQUUYsT081oyAUrJD 8nUFRfm7pW8/I2skUIuSTO6WDBHDRVmGGcz2pjPLxDLAWib/J+sBgKabbXOv5Mwa+QQg Kj6sRdbM4mBrc85cDKdy0lQXb1Z5Fbw43znd0WsFjpBpHudguDAX9UQWOzcfotew0X9y b2MVjxlA8oFxLfx825Mo+63F0knR7uGzkEP0DGkRqJWNeeALRh0kJPDpKr/3yyKt+vIk qa/Q7B8jhj8Wy24Awa8eos63oDeU6YGZ7kerY8OoWLeNuBkoV36Xrzaae8MVh49TJhMy o2dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KYWxTLoM; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cw10-20020a170906478a00b007919c624eadsi1159315ejc.522.2022.12.02.09.22.13; Fri, 02 Dec 2022 09:22:36 -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=@kernel.org header.s=k20201202 header.b=KYWxTLoM; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233901AbiLBQSx (ORCPT + 82 others); Fri, 2 Dec 2022 11:18:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234034AbiLBQSL (ORCPT ); Fri, 2 Dec 2022 11:18:11 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03636DA216; Fri, 2 Dec 2022 08:16:47 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 9DC07B821EF; Fri, 2 Dec 2022 16:16:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A092C433C1; Fri, 2 Dec 2022 16:16:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669997804; bh=g8YHlGQGI5+kOudmGxtQLpBJJ0VXh/b1x75GjPjycds=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KYWxTLoMH80ob3tE9WkideVGBL6HUpVaeZ5ha7q+gWJ8kjI8kW66x0wMfXqBvNl+s PJQd5K5KQZRPbx0Sf1colbtpMw5EMb5frdHCbG7WXSId49CmBIqnhXOgw/SvWlMLZW /pZ+eLV9PZFDyxqIlZn7RE/zRC50mbZ565dHUtozufFIjPr8JhTyW/GjdODiw5zipj PX+JcqHJ1LzyhAC0rPUsYW4UiIwEtvsY0IeeGfNCYu7LMAw735b5jv3CF0bl//grQn tO5nU021aoxzEyOal7ng3ohpzMfzsMpB4YvPYEu74tLUPOY8AjYGByia8fsEgC3mBx 4QsQIkCbNju3g== From: ojeda@kernel.org To: Miguel Ojeda , Wedson Almeida Filho , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Wei Liu Subject: [PATCH v2 27/28] rust: types: add `Either` type Date: Fri, 2 Dec 2022 17:14:58 +0100 Message-Id: <20221202161502.385525-28-ojeda@kernel.org> In-Reply-To: <20221202161502.385525-1-ojeda@kernel.org> References: <20221202161502.385525-1-ojeda@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 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, } Signed-off-by: Wedson Almeida Filho Reviewed-by: Wei Liu [Reworded, adapted for upstream and applied latest changes] Signed-off-by: Miguel Ojeda --- rust/kernel/lib.rs | 1 + rust/kernel/types.rs | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 rust/kernel/types.rs diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index a3abc110ff97..53040fa9e897 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -31,6 +31,7 @@ mod static_assert; #[doc(hidden)] pub mod std_vendor; pub mod str; +pub mod types; #[doc(hidden)] pub use bindings; diff --git a/rust/kernel/types.rs b/rust/kernel/types.rs new file mode 100644 index 000000000000..3b0c44769708 --- /dev/null +++ b/rust/kernel/types.rs @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Kernel types. + +/// A sum type that always holds either a value of type `L` or `R`. +pub enum Either { + /// Constructs an instance of [`Either`] containing a value of type `L`. + Left(L), + + /// Constructs an instance of [`Either`] containing a value of type `R`. + Right(R), +} -- 2.38.1