From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=202.12.124.155 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796082200; b=PIo3o2exZEnXNtxZEVyyf11LUkUjoGi8JZ8bTrEPLHbwk4idycXrVzFyQUoB7i4PK5ub hjgyO3QAJxinkw5vqreSG22IR7XHSVzyJfUWWZh6ycCf1UcJZV41I34o/pdpFdmVfqo7A QJVwfUcEzBje5yjgr2yhnU1tWZS6ES9MaHBVKF4bNme2XVbnFtRs59oaaeCGMx6e2H53I eZNTJ+qOfNMh0m3bMZFKc9Lj6WhdiVjPx8ZQH1INtPO7WH2C4RaktNTqghbNYI0YMgPxq q1T9cVOegGtzQzFnfa8dwJF8xcvvBIH50MLUOS2CJ0V0wvW/KJdRhW7tz0p3HB2KqSQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796082200; h=DMARC-Filter:Received:Received:DKIM-Signature:DKIM-Signature: X-DKIM2-Info:DKIM2-Signature:X-DKIM2-Info:Message-Instance: X-ME-Sender:X-ME-Received:X-ME-Proxy-Cause:X-ME-Proxy:Feedback-ID: Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=9i0q8Ccsofdv/TiyfDwuztb79P9eWfYnDLJyGmBTy/4=; b=ORHvnpxCgLsvmPRxWjv+XPNQrunyPjpLr50hAvXgU90ajHGY6vCGoLQS26Jnh2hTNICc r+DJvOpH2cLNYQ9XYx6D84zw+ahG/4ZoMGih7hwePx0R9oocG+DUhIIpgdx1Q7QzG54+l eSLJp6yoH1AmMjjFHpxAPpRVSU9nSTJ0WHXbfCYgXaLtCdyUOcKgC7S3j6lVLyIWXnAyP ySXC+RomKAjWiOduvGjh/cFgGSM+beUyt4ERJKodNwPuDC7nUapjGtxvigP/VGNkW35/o 2KTU3/N7kmPbZv7k8SIQ2WH1SM8B+vUAUoNO/CHKkdZxcEEuWwOBYMzqZA32jImGnJg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=flapping.org; spf=pass smtp.mailfrom=flapping.org; dkim=pass header.d=flapping.org header.i=@flapping.org header.a=rsa-sha256 header.s=fm2 header.b=cJmufquC; dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=U09Qi89n; arc=none smtp.remote-ip=202.12.124.155 Received: from fhigh-b4-smtp.messagingengine.com (fhigh-b4-smtp.messagingengine.com [202.12.124.155]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 00B44606A32E for ; Mon, 30 Nov 2026 23:43:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 00B44606A32E Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=flapping.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flapping.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=flapping.org header.i=@flapping.org header.a=rsa-sha256 header.s=fm2 header.b=cJmufquC; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=U09Qi89n Received: from phl-compute-02.internal (phl-compute-02.internal [10.202.2.42]) by mailfhigh.stl.internal (Postfix) with ESMTP id 45E3E7A04DB for ; Mon, 30 Nov 2026 18:43:19 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-02.internal (MEProxy); Mon, 30 Nov 2026 18:43:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flapping.org; h= cc:cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:message-id:mime-version:reply-to:subject:subject:to :to; s=fm2; t=1796082196; x=1796168596; bh=9i0q8Ccsofdv/TiyfDwuz tb79P9eWfYnDLJyGmBTy/4=; b=cJmufquC7qP2uVRFiAGzrjC/t9meVbBD+o1wM FqKy7ikvtkd1xazUop59L3LP7sort58eDVPbQ22U8/oXsN0bafUX9wngxOQ2gPB6 LpLn3g0I6FTMeRMxR5qEURePUVAR6odH4/hP8vM6oI5/Wn/gtoGhgG0FCfPYrRV1 S2YOvfPoJu8CGZwcoU1FJwbR2XY1F59sj/AjSLt3+Wo12WoaHw2KCdTNMjnuI/5f TkrG/GOpbF6W5nafxvIaZbVcp2GTIvPQPWMbOvxcdN/ZhBlKByFdXu2jG8XR/UMS dnDxbxgTfwNKgheEzJfIisg16+4l4g6ZRNSsOqR6BaOZy1W6w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:message-id:mime-version:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1796082196; x=1796168596; bh=9i0q8Ccsofdv/TiyfDwuztb79P9eWfYnDLJ yGmBTy/4=; b=U09Qi89nAUktDJ9Lg62tb5IsW/U3FasVaOyCLXvVrM33GHqWswg kw5PV4vAGi7lUvdXKl0oQLvSXqHMLukdvYaIPhfEBrMe3VBQHuWtHhtZno57OgIj uy9daVudyVKealxG9UiMEDNyv8YXkOfspYMyQh2kDhb/fZbX2G7Dek6DwIs21goD /LVQazUxpXoIFRjDBccbP8ELy59m3E4mYB548MNxFljQ/5Tfb5LVPhuZTb4dbJrc hh8YfGoWyt4V947lbI9/zT8rIilZJuj2lzvLNU3iUkEhKKoj1ohShuJ5GkFxzTHz qAZCZG0eqUWJ7mkwCvCLrJP1M0J/099PoQA== X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=sign d=flapping.org a=rsa-sha256; DKIM2-Signature: i=1; m=1; t=1796082196; d=flapping.org; mf=PHRvbW9AZmxhcHBpbmcub3JnPg==; rt=PGxpbnV4LWRvY0B2Z2VyLmtlcm5lbC5vcmc+; s=fm2:rsa-sha256:Z4o4eDy1cB6XOCmkWe/1OQmEyE8RmIkTAuMG7i9fjPynmPA hnUT+dsl6IBrQizyoQ4b/koLjlrh05AcqLEkJQXE4Qda7yrYzoABAveCVeDOOYsU 2Luy0R21UkK860yR7RG0cYG48NCZOkcJcUEQMAs7VMy2VgT5mP6vMbgzRu4YyJit VNZ70WPqetoFA9wNyxZjlUHvOxu6Wt+aKawsOLYzdymhpCU+Jnl7YrUQZIvRUG0L t0pjAhBn8wwFNaQuLyC9976vaFFxKCOKq3o3hzL2z6bUuhhRcaPTgbgoob4pFHWZ 2eMcO/M7IUvS59xjo9+dHCjBa+5EOWyvSM6P4xQ==; X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=mi-m=1; hc=9; hn=cc,content-transfer-encoding,date,feedback-id,from, message-id,mime-version,subject,to; Message-Instance: m=1; h=sha256:wf4lwNDYc7AflJnVIciUozOQkjAR1yptfqag1H4s5+Y=:/yeud2b/PDdv5msIuzviqeIHMWcrrV7CITmivbfW4lk=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTFGLfg6rEQekt4U2U+Q93lvrdPiMtY0vus9/y7CIFl+lKXGaE0uaY8cDSYOAEYFAc yazlmX7hqm+wlakeKDqFIW/5dHCxAsboFqlYZpgopcOG5UX+UO6WiN+U8al5S+8zcfzT5T +vJI52vkaLXQE7VMOU3mgmTsyzn11YvAhvKir6qyu7oGofp3bKpp6AceRWP59sR6KTVBI/ daKSyu+s1hMgay7cr928/1LrKtvQseN9EdnBra/TTYZRJGYeynycnsryTrVC13iWfb+Aua QzVxungK56w3nl+qgzwyo1LaCVM8l2S/uvPUWs0JAqoWyKS1+swZ3NiWYPe71MGz8lAtpN WBNpCSCbYpL7tqA1p+OG4nZQ/pL7FQRmb0Pdhozz1DQhZvsW0WPLb/aKsme4m5JI/ibfuf nTCoRFtYdGwHIGY+pgT5Eoo0xX7QKiMIEosH7kT6IgsWvtTAsHZ3f3u9DJnpFRf3202q7m yUJvnZkCc8jb2yBTk3Rj7UyK9Yt8Ybi/EP9qZmJ+Q9m3Jb+Jgo7DGk9sWNaKxgoIGS/FHJ TjCMStJFzO/q/nYh6Jk7l2bco7XpDe8vKSiPXaA34SaKYokazga36DhJyCd4ZDBWDmnR9w qNX1B/VugN+v8HArIR0MrnNZ50x6vSaBXZbQmwFFMxlrpud4Cy7FLM3C2FVw X-ME-Proxy: Feedback-ID: i51fe4b43:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 30 Nov 2026 18:43:11 -0500 (EST) From: FUJITA Tomonori To: corbet@lwn.net, ojeda@kernel.org Cc: a.hindborg@kernel.org, acourbot@nvidia.com, aliceryhl@google.com, bjorn3_gh@protonmail.com, boqun@kernel.org, dakr@kernel.org, daniel.almeida@collabora.com, gary@garyguo.net, lossin@kernel.org, rdunlap@infradead.org, skhan@linuxfoundation.org, tamird@kernel.org, tmgross@umich.edu, work@onurozkan.dev, linux-doc@vger.kernel.org, rust-for-linux@vger.kernel.org, FUJITA Tomonori Subject: [PATCH v2] docs: rust: add guidelines for Display and Debug Date: Tue, 1 Dec 2026 08:43:07 +0900 Message-ID: <20261130234307.750295-1-tomo@flapping.org> X-Mailer: git-send-email 2.43.0 X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: FUJITA Tomonori The kernel crate has no written rule about when a type should implement Display and when it should implement only Debug. This came up in the review of a patch that adds Display for Delta. Add a section that follows the usual Rust convention, with one kernel specific point about types that correspond to C types. Also say that the output of Debug may change, and that a type should provide a method when a stable output is needed. Link: https://lore.kernel.org/rust-for-linux/87se19qgeu.fsf@t14s.mail-host-address-is-not-set/ Signed-off-by: FUJITA Tomonori --- v2: - Remove the anchor from the Display link (Miguel) - Say that the Debug output may change (Miguel) - Suggest a method for a stable output, e.g. Delta::as_nanos (Miguel) v1: https://lore.kernel.org/rust-for-linux/20261115214025.2122718-1-tomo@flapping.org/ --- Documentation/rust/coding-guidelines.rst | 26 ++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Documentation/rust/coding-guidelines.rst b/Documentation/rust/coding-guidelines.rst index 3198be3a6d63..e32bda74fd29 100644 --- a/Documentation/rust/coding-guidelines.rst +++ b/Documentation/rust/coding-guidelines.rst @@ -333,6 +333,32 @@ That is, the equivalent of ``GPIO_LINE_DIRECTION_IN`` would be referred to as ``gpio::gpio_line_direction::GPIO_LINE_DIRECTION_IN``. +Formatting traits +----------------- + +Rust kernel code follows the usual Rust convention that ``Display`` should only +be implemented when there is a single obvious way to format the values of a type +as text: + + https://doc.rust-lang.org/core/fmt/trait.Display.html + +For a type that corresponds to a C type, a format that the C side already uses +also counts as such an obvious way, e.g. the output of a ``printk`` format +specifier such as ``%pe``. + +On the other hand, some types have no single obvious format. For example, a +quantity with a unit, such as ``Delta`` or ``Hertz``, can be printed in +different units and with different precision. + +For such types, ``Debug`` should be implemented instead of ``Display``. Its +output is for debugging, so any format that is useful for developers can be +used. Usually ``#[derive(Debug)]`` is enough. + +The output of ``Debug`` may change, so other code should not depend on it. When +a stable output is needed, the type should provide a method for it, and users +should call that method instead, e.g. ``Delta::as_nanos``. + + Lints ----- base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244 -- 2.43.0