Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1005878rwb; Thu, 10 Nov 2022 09:59:44 -0800 (PST) X-Google-Smtp-Source: AMsMyM6awlW0hx8gTJsaxjik/aY9irNiNLSnkJcmgSizUmUohjdo630+hIkivL21UVmhKl+HflXS X-Received: by 2002:aa7:8ed0:0:b0:56b:b8d8:f564 with SMTP id b16-20020aa78ed0000000b0056bb8d8f564mr3097250pfr.46.1668103184389; Thu, 10 Nov 2022 09:59:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668103184; cv=none; d=google.com; s=arc-20160816; b=K9ueCFqRzwqyrgH+za8dpUii2GNaReeCQUKJH+dJyneGz8SstItFOH4a+ytS8CKvOl JpWynZYdZjEa54SCjWvX1438yCWPv33OPh5WzWcS4OE5dLf9gNYcA3mpLW8JHP+HwWv9 VWmn5k1a4swufVtzZf7viQ684FRGp7Bdlwbgz2iLpzZs/RkR2bnsqywK6g1bddE1D/9p SbbuhRAna0Pjf4tJuvZbXz5Dq84cYWp/Y27r1a6ZD2iQxUOim1IruMzv3LaUbKsoFpOh fWUU+KjtFX+JqT2ql+y00QlsNMH1Lp4pouLuBhYiOAmMNXT2sjbn1LFIIdWzAzJpyqnv wYCA== 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=cqHcsgnZOKZZBs/V+M5lRsQokgkx4dee3bhdEX/GoLQ=; b=wDSfiBLFUvUyuxQ+8OKcKMNpwMoFlgHwKzekB3wbH2AprA2c0ByB7AWhEMpQ+H4YDW wWmWWvCJeyRav22g1iea2GMyluvOsDRCnMGBDQ9sPd0qCtve55NEZ6tdOFIszxXZK/L1 zI8LPw/jxEqK5L/IIT1wu600OoepY7+VKmLijfTXLnb9GHM4e0U8/lYz5inpfOEeAK1R uPncsqHIvn2sgLxjpibxawUCWBp6tDqCyTy4udG0dbMn60adSennt0r1g6CTKf8QeMl1 bY/ABnWiVJQ2fa1jVSpUfu/P+G2OgJQ/661Ao3L4fVyXXKRtC8vUcq/zwZlbGUbfDGad 6ltg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Yp/6XFlz"; 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 q15-20020a63d60f000000b0046ee9f16e3dsi20910333pgg.671.2022.11.10.09.59.32; Thu, 10 Nov 2022 09:59:44 -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="Yp/6XFlz"; 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 S232509AbiKJQo4 (ORCPT + 92 others); Thu, 10 Nov 2022 11:44:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232516AbiKJQoR (ORCPT ); Thu, 10 Nov 2022 11:44:17 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7295C450B4; Thu, 10 Nov 2022 08:43:26 -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 11C77B82251; Thu, 10 Nov 2022 16:43:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA8D4C433B5; Thu, 10 Nov 2022 16:43:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668098603; bh=I3b0Z7RHs3m0QbSSsLLKwiQESMTWz+K564vWJV2JsjA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Yp/6XFlz+k04kCIlhS2B7ArlTF8uHXzFiMTnjRyUTjiwb4202IV8ifYnWqDb0mU+G yfICCMeY46vT+WeRhUyJuToCRSCPgt8qdqSJuizlKRzNeflPzGSyO/ZCEuIfhErpGM 0COeovEJQIyeGhyYcArZACHaQFby9VJdFW80t+7Lcmzb/3G0P4ocVCPY+V3gZ0u6y2 YorzeDzm32SzM8hpLKcB59M8689V8Pmgh2d7CpI6V67oa3UqYcuCAJXiY5/RQU7KM2 Vix8vowoVr8xSF7f1Ui7Ed8/AV7G7x/zteQ5HQSxeAqg5bTmc7Md0hsusR7qwG2E+1 FUW9QoBga1rQw== From: Miguel Ojeda 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 Subject: [PATCH v1 22/28] rust: str: add `fmt!` macro Date: Thu, 10 Nov 2022 17:41:34 +0100 Message-Id: <20221110164152.26136-23-ojeda@kernel.org> In-Reply-To: <20221110164152.26136-1-ojeda@kernel.org> References: <20221110164152.26136-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 Add the `fmt!` macro, which is a convenience alias for the Rust `core::format_args!` macro. For instance, it may be used to create a `CString`: CString::try_from_fmt(fmt!("{}{}", "abc", 42))? Signed-off-by: Wedson Almeida Filho [Reworded, adapted for upstream and applied latest changes] Signed-off-by: Miguel Ojeda --- rust/kernel/str.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs index 877148b77e71..ffac633423db 100644 --- a/rust/kernel/str.rs +++ b/rust/kernel/str.rs @@ -592,3 +592,9 @@ impl Deref for CString { unsafe { CStr::from_bytes_with_nul_unchecked(self.buf.as_slice()) } } } + +/// A convenience alias for [`core::format_args`]. +#[macro_export] +macro_rules! fmt { + ($($f:tt)*) => ( core::format_args!($($f)*) ) +} -- 2.38.1