From patchwork Tue Feb 7 18:52:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Boqun Feng X-Patchwork-Id: 54045 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp3022351wrn; Tue, 7 Feb 2023 11:01:57 -0800 (PST) X-Google-Smtp-Source: AK7set8CGAok8BhotybvLet+QB2gRzCEXgQazvXkZ0EVBX1XuFATYzrKF50q+KIi1K3BktWdZTe4 X-Received: by 2002:a17:906:4748:b0:888:db6b:5fa9 with SMTP id j8-20020a170906474800b00888db6b5fa9mr5119906ejs.67.1675796517229; Tue, 07 Feb 2023 11:01:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675796517; cv=none; d=google.com; s=arc-20160816; b=nD3Bnt1K84uyP96ICwnGfP/4dMvIHLSBl+Jpnl6k46GaiOBbYcc05SEZO4tC+08IaR t18QH9E13jupb/gTtYeJTXMucE3YqTdX1So73U/ymIFVKVtODFvt2c24IfY3rvwhy8Ro qheQOCwFZMkCoIiRYeyVM96rsQ25SJNnbbo08RfJMI7bbSXAMcw3E/7D5sFUYGbraWZJ 0Lbn4u6MMawzdSkd+6SdRKIR/EbYH5HXTznDAmRnkKfaCdJgzGhojKuQvlOgbD/exOsO RujjwVjej6ATUt+FE0m8dN+nMZeUo62D7sAIZd3O3lu3OFRqqU1LkSXdqZy8d3t7zCif XIrw== 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 :feedback-id:dkim-signature; bh=wmko9U6xz9AxcE4cRj9bysFLw2CXZVZtRuLkE86PSJA=; b=yFFx59mcgYsn39zMP229svAbESDbEsu1ZUtxz3xPAX7nrMxBtC2t938b9QENaItKOB pSrBiF6wmGZuq5h3L7MWmCvKf7a9qbtmsOiCj1Llucw6qEft7NajvJj67+D27eY1qMjT kYzopjtAIzVsY4rqF646H0fwwGB+/cCc1ILtAM+HfG959XBp1H1FtHtAzosiTR+k2ixu Rwgod3z09ZhKW8Abr9MtRd1jj9U+NiQt2gtYq7BFgSldvwJzSHnH+vpXEW5XiIJrwnPw crJ0bS+BB/B8RsSE7KGSTuu0x6N5RN+FVB+1p5HiAsm21474IS4TgTuMuGDwOoMgZdFa oWsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=kNZGlZmQ; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f1-20020a170906738100b00889c115cf70si18845995ejl.190.2023.02.07.11.01.33; Tue, 07 Feb 2023 11:01:57 -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=kNZGlZmQ; 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 S229732AbjBGSwx (ORCPT + 99 others); Tue, 7 Feb 2023 13:52:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232212AbjBGSwv (ORCPT ); Tue, 7 Feb 2023 13:52:51 -0500 Received: from mail-qv1-xf29.google.com (mail-qv1-xf29.google.com [IPv6:2607:f8b0:4864:20::f29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2CF49EF0; Tue, 7 Feb 2023 10:52:48 -0800 (PST) Received: by mail-qv1-xf29.google.com with SMTP id k28so9724401qve.5; Tue, 07 Feb 2023 10:52:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:from:to:cc:subject :date:message-id:reply-to; bh=wmko9U6xz9AxcE4cRj9bysFLw2CXZVZtRuLkE86PSJA=; b=kNZGlZmQpFMwNMGoZy2/mcgEFIa+lvEq0MYcXzAQK3qX+HTN5H4fwMzEe81b5O880H D22mUtuh3l92jbls5hULW1+M4F1Rqfulm1du6ml7mgcQClVdolH6xoLgODA2PDm8zHp6 UtXY/bsl8CSTLthlOmblI3nD8MD4C4aGPo6WfuKJvrKqAAfmYn0D7Ft0jc5GTky+rFWn 9tczATkj8F7CdwArhAxU3evcSLF1cY2rM0/A9UozcwmQ6T8ceyCmaIDW6lnwQ93xfu+Y +sfF/oHkmW8mjjesgwd63pWzyMRlDmoxcAaFG9ZyJReGQGRVkMFVwDel+Q9yvvJtDo1R W9ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=wmko9U6xz9AxcE4cRj9bysFLw2CXZVZtRuLkE86PSJA=; b=SL9Zje1jVu6IIFHJCxb7WDMxB1DrXQWEbZ0bwYwdv3mgvghOnVMwH1yhEXzXCegVGG wAJU74WGn+IB02/1Aur76pvDY656wDTntL3BPpW2m29VDShxImrI9KTTHQp0cRkiOWqu nHbIprVNQzRC5QsJn1iD8DwO4p9vfNlPwX2J9MtVVstcRxCY2ul+FrADeVFIv2RcPoPz dL8wwRIA+gi1JsXn6IxX4Fsv3cKwDQqF1q9xpzcBrvYshRDFAnmTCspRcK7UsLUeYJb8 M/snQ/g+XxIlB2CJl506Jnm0B8sdvywG4jNv92V5DwOQ6B3AbiDBFP09QlOBcERxYxqQ 2rdw== X-Gm-Message-State: AO0yUKXaNWw61PDX9d5A0RgfNlStjbDJh/RbB04MOdou4FlAtal0T6uP XgYOzk0a5jHOtgyJud+74xY= X-Received: by 2002:a05:6214:5298:b0:56b:ee96:4d32 with SMTP id kj24-20020a056214529800b0056bee964d32mr6706308qvb.51.1675795967835; Tue, 07 Feb 2023 10:52:47 -0800 (PST) Received: from auth1-smtp.messagingengine.com (auth1-smtp.messagingengine.com. [66.111.4.227]) by smtp.gmail.com with ESMTPSA id p13-20020a05620a22ad00b007204305dee4sm9840932qkh.19.2023.02.07.10.52.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Feb 2023 10:52:47 -0800 (PST) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailauth.nyi.internal (Postfix) with ESMTP id D8DA527C0054; Tue, 7 Feb 2023 13:52:46 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Tue, 07 Feb 2023 13:52:46 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrudegkedgudduhecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeeuohhq uhhnucfhvghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtghomheqnecuggftrf grthhtvghrnhepheefvddtkeejtdelffekgfdtheeugeefffekgefghfejhfduieekjeeg heetvdefnecuffhomhgrihhnpehpthhrrdgrshenucevlhhushhtvghrufhiiigvpedtne curfgrrhgrmhepmhgrihhlfhhrohhmpegsohhquhhnodhmvghsmhhtphgruhhthhhpvghr shhonhgrlhhithihqdeiledvgeehtdeigedqudejjeekheehhedvqdgsohhquhhnrdhfvg hngheppehgmhgrihhlrdgtohhmsehfihigmhgvrdhnrghmvg X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 7 Feb 2023 13:52:45 -0500 (EST) From: Boqun Feng To: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Cc: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Vincenzo Palazzo , Will Deacon , Peter Zijlstra , Mark Rutland , Greg Kroah-Hartman , =?utf-8?q?Sergio_Gonz?= =?utf-8?q?=C3=A1lez_Collado?= , Finn Behrens Subject: [PATCH v2 1/2] rust: sync: impl {Debug,Display} for {Unique,}Arc Date: Tue, 7 Feb 2023 10:52:15 -0800 Message-Id: <20230207185216.1314638-2-boqun.feng@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230207185216.1314638-1-boqun.feng@gmail.com> References: <20230207185216.1314638-1-boqun.feng@gmail.com> MIME-Version: 1.0 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757200008644083885?= X-GMAIL-MSGID: =?utf-8?q?1757200008644083885?= This allows printing the inner data of `Arc` and its friends if the inner data implements `Display` or `Debug`. It's useful for logging and debugging purpose. Signed-off-by: Boqun Feng Reviwed-by: Vincenzo Palazzo Reviewed-by: Vincenzo Palazzo Reviewed-by: Gary Guo Reviewed-by: Andreas Hindborg Reviewed-by: Björn Roy Baron --- rust/kernel/sync/arc.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs index 519a6ec43644..e6176d9b5b29 100644 --- a/rust/kernel/sync/arc.rs +++ b/rust/kernel/sync/arc.rs @@ -22,6 +22,7 @@ use crate::{ }; use alloc::boxed::Box; use core::{ + fmt, marker::{PhantomData, Unsize}, mem::{ManuallyDrop, MaybeUninit}, ops::{Deref, DerefMut}, @@ -522,3 +523,27 @@ impl DerefMut for UniqueArc { unsafe { &mut self.inner.ptr.as_mut().data } } } + +impl fmt::Display for UniqueArc { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::Display::fmt(self.deref(), f) + } +} + +impl fmt::Display for Arc { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::Display::fmt(self.deref(), f) + } +} + +impl fmt::Debug for UniqueArc { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::Debug::fmt(self.deref(), f) + } +} + +impl fmt::Debug for Arc { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::Debug::fmt(self.deref(), f) + } +} From patchwork Tue Feb 7 18:52:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Boqun Feng X-Patchwork-Id: 54046 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp3022357wrn; Tue, 7 Feb 2023 11:01:57 -0800 (PST) X-Google-Smtp-Source: AK7set/8AS3rQFRjN3t+okJHt4sNQSE5wCHSotInXIi9RBgcAntPzMqz3ZAMlsWb9/n5gsO4XYVH X-Received: by 2002:a50:9b1b:0:b0:47e:eaae:9a5b with SMTP id o27-20020a509b1b000000b0047eeaae9a5bmr4769549edi.42.1675796517701; Tue, 07 Feb 2023 11:01:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675796517; cv=none; d=google.com; s=arc-20160816; b=RF+0d8wIv/7eqOYocEFkKY163jMeoS6w4vCi156KPx9FEhGrRni9n9ror1vNxW6+CT S9td6bPV/IQ2XH+d+HxsvM0OEagy/USjaPGTA0HAwJ6TnnwlMcrxdlKrY0ui8jzLUaqb i2eWC8wO5tqft236fKBwOfkViHcka1MXyKRtov+feA/d1pn1i+FNkbqwmAknTRbEN7zo 9naqHteCLER37timVUDtBQVv01m1tkeBkckdfhRxcQ3b2oqx7xgq73L4QearKCBxGrC0 xA22GLk1urTddLGLrrwH2vIv+vzTAHIRxHPHWzKyEXMijlu4sy/JZOnRTKZAkgI+7jZ9 eseQ== 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 :feedback-id:dkim-signature; bh=pw0ByORIxbzjhrXTdLg80T0eGpn6Y+jK2lz5pJ++YH8=; b=XjdC8sKlVENhdukmQdJz9cnrocDVNYMmpKTfqaY9bL8PaHbToOdisL1rMgx4cr4Pxj x7I2xPY8C1f92wHgqVHSQGS8DfpydleDk0X4XWfY2H/aOIxysdC0iITXJeVSfRI7n5g8 xzlxgGxX9IOHx9n1oq45OuTaoWBq5IL6nOGot0F74in5zNZ+29/cz8WOFnhqa9EVD9lF jT1gm5YoKbGaK5bwfmPn2jki0iJINnTFyT04Kl8bou/VaDFoRi52irgSNQI2sMZ2dbhR rCxr4DT8hj4ILiWWOFIKmvSKZDtivWdCikQBQnwqcJ30nOK4iTLzAiv4l2W3H+mRJgkm zvJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ZncQL7xo; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w9-20020a170906968900b0088ef8637b30si15088441ejx.568.2023.02.07.11.01.34; Tue, 07 Feb 2023 11:01:57 -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=ZncQL7xo; 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 S232016AbjBGSw5 (ORCPT + 99 others); Tue, 7 Feb 2023 13:52:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232361AbjBGSwv (ORCPT ); Tue, 7 Feb 2023 13:52:51 -0500 Received: from mail-qt1-x82b.google.com (mail-qt1-x82b.google.com [IPv6:2607:f8b0:4864:20::82b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B251103; Tue, 7 Feb 2023 10:52:50 -0800 (PST) Received: by mail-qt1-x82b.google.com with SMTP id c2so17892199qtw.5; Tue, 07 Feb 2023 10:52:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:from:to:cc:subject :date:message-id:reply-to; bh=pw0ByORIxbzjhrXTdLg80T0eGpn6Y+jK2lz5pJ++YH8=; b=ZncQL7xoNfDQKYP2yNCeYPlLtuGapA/miBtdGv+YudqBd6A4483uU9LQ9tZ7Z6MALU WdMoI7xGiho0iARaGqGVxHmQIcesZ59Y2/6KR572sn1DMC0CfV2MqOx5rN1c5zBCtyJ1 dt3tEWWt5tht3s9NrenVZa/Y4XcPWOWTZKtSsfLVlzVzPyjD2OxC+TEzgqLgVqS2ZO7K nV27ZVwikFgP1d6l67GLr/UKOM/cU93+dU7luJ1MGhMvX01hv/BWabyWiTS4waYuThA+ GzZxf2XjNpnO8ORApL/h1OsjWrTfp9ol35xjPhuIxTCJobkyNyTHzmsUugyROy4HsyIj qLWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=pw0ByORIxbzjhrXTdLg80T0eGpn6Y+jK2lz5pJ++YH8=; b=3fQdLBFziCr6fxyviDPq7KLC/c0fhmLLhRvTz/6ujEzshmqatLKKavVWpafsOvg2IG B9+cTftS2iYcG4+HtP+4eRcJo8chEXjk1xtfctVAPznRXitTtKbw5ruz6MgsPMZ27uRk 1YY0XApK+bys4BIsQfdlF7zLb7ef9Yjy5lJ1jovf+Zc+WYYYCFsI+9R11wYduqfEfUNp hiKuQMNWzBFUf+gcK1hWZaK+2ACKvNAUd7zmL2VIekpyNQBWFe3uiuL6hdu0IIhIzj7h VwDfceJg6Iu/5dMK0qJjp+RY6MhB+832/j6RMPtei6de0ktEZqObXtkP5PUyNhJR+h1x cpTw== X-Gm-Message-State: AO0yUKUs8rXtY9agCrZEObIhfkTbeznsAoodHIZFvw6DvoKDaBkrNGWk 1Us496UvPpoOAeh3N3I+EpcxgTrJQP4= X-Received: by 2002:ac8:7fc2:0:b0:3ba:1360:ec0a with SMTP id b2-20020ac87fc2000000b003ba1360ec0amr7070190qtk.41.1675795969132; Tue, 07 Feb 2023 10:52:49 -0800 (PST) Received: from auth1-smtp.messagingengine.com (auth1-smtp.messagingengine.com. [66.111.4.227]) by smtp.gmail.com with ESMTPSA id f9-20020ac84989000000b003b869f71eedsm9729924qtq.66.2023.02.07.10.52.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Feb 2023 10:52:48 -0800 (PST) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailauth.nyi.internal (Postfix) with ESMTP id 4022D27C0054; Tue, 7 Feb 2023 13:52:48 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Tue, 07 Feb 2023 13:52:48 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrudegkedgudduhecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvfevufffkffojghfgggtgfesthekredtredtjeenucfhrhhomhepueho qhhunhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtf frrghtthgvrhhnpeehffeiheehhfevhefhleefjedtiedtjefhveekfeejiedugeekkeeu uefhieevkeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpegsohhquhhnodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdeiledvgeeh tdeigedqudejjeekheehhedvqdgsohhquhhnrdhfvghngheppehgmhgrihhlrdgtohhmse hfihigmhgvrdhnrghmvg X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 7 Feb 2023 13:52:47 -0500 (EST) From: Boqun Feng To: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Cc: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Vincenzo Palazzo , Will Deacon , Peter Zijlstra , Mark Rutland , Greg Kroah-Hartman , =?utf-8?q?Sergio_Gonz?= =?utf-8?q?=C3=A1lez_Collado?= , Finn Behrens Subject: [PATCH v2 2/2] sample: rust: print: Add sampe code for Arc printing Date: Tue, 7 Feb 2023 10:52:16 -0800 Message-Id: <20230207185216.1314638-3-boqun.feng@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230207185216.1314638-1-boqun.feng@gmail.com> References: <20230207185216.1314638-1-boqun.feng@gmail.com> MIME-Version: 1.0 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757200009008470948?= X-GMAIL-MSGID: =?utf-8?q?1757200009008470948?= This both demonstrates the usage of different print format in Rust and serves as a selftest for the `Display` and `Debug` implementation of `Arc` and its friends. Signed-off-by: Boqun Feng Reviewed-by: Björn Roy Baron Reviewed-by: Finn Behrens Reviewed-by: Vincenzo Palazzo Reviewed-by: Gary Guo Reviewed-by: Andreas Hindborg --- samples/rust/rust_print.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/samples/rust/rust_print.rs b/samples/rust/rust_print.rs index 8b39d9cef6d1..165a8d7b1c07 100644 --- a/samples/rust/rust_print.rs +++ b/samples/rust/rust_print.rs @@ -15,6 +15,30 @@ module! { struct RustPrint; +fn arc_print() -> Result { + use kernel::sync::*; + + let a = Arc::try_new(1)?; + let b = UniqueArc::try_new("hello, world")?; + + // Prints the value of data in `a`. + pr_info!("{}", a); + + // Uses ":?" to print debug fmt of `b`. + pr_info!("{:?}", b); + + let a: Arc<&str> = b.into(); + let c = a.clone(); + + // Uses `dbg` to print, will move `c`. + dbg!(c); + + // Prints debug fmt with pretty-print "#" and number-in-hex "x". + pr_info!("{:#x?}", a); + + Ok(()) +} + impl kernel::Module for RustPrint { fn init(_module: &'static ThisModule) -> Result { pr_info!("Rust printing macros sample (init)\n"); @@ -43,6 +67,8 @@ impl kernel::Module for RustPrint { pr_cont!(" is {}", "continued"); pr_cont!(" with {}\n", "args"); + arc_print()?; + Ok(RustPrint) } }