Rust for Linux List
 help / color / mirror / Atom feed
* [PATCH] docs: rust: Add error handling sections
@ 2025-01-07  6:21 Dirk Behme
  2025-01-07  6:21 ` [PATCH] rust: error: Extend the Result documentation Dirk Behme
  2025-01-12 13:45 ` [PATCH] docs: rust: Add error handling sections Miguel Ojeda
  0 siblings, 2 replies; 6+ messages in thread
From: Dirk Behme @ 2025-01-07  6:21 UTC (permalink / raw)
  To: rust-for-linux; +Cc: dirk.behme, ojeda

Add error handling sections to the documentation and use it
to link to the existing code documentation. This will allow
to extend that documentation, use intra-doc links and test
the examples.

Link: https://lore.kernel.org/rust-for-linux/CANiq72keOdXy0LFKk9SzYWwSjiD710v=hQO4xi+5E4xNALa6cA@mail.gmail.com/
Suggested-by: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: Dirk Behme <dirk.behme@de.bosch.com>
---
 Documentation/rust/coding-guidelines.rst | 8 ++++++++
 Documentation/rust/testing.rst           | 8 ++++++++
 2 files changed, 16 insertions(+)

diff --git a/Documentation/rust/coding-guidelines.rst b/Documentation/rust/coding-guidelines.rst
index a2e326b42410f..27f2a7bb5a4a2 100644
--- a/Documentation/rust/coding-guidelines.rst
+++ b/Documentation/rust/coding-guidelines.rst
@@ -373,3 +373,11 @@ triggered due to non-local changes (such as ``dead_code``).
 For more information about diagnostics in Rust, please see:
 
 	https://doc.rust-lang.org/stable/reference/attributes/diagnostics.html
+
+Error handling
+--------------
+
+For some background and guidelines about Rust for Linux specific error handling,
+please see:
+
+	https://rust.docs.kernel.org/kernel/error/type.Result.html#error-codes-in-c-and-rust
diff --git a/Documentation/rust/testing.rst b/Documentation/rust/testing.rst
index 568b71b415a45..4e2bc3b971e99 100644
--- a/Documentation/rust/testing.rst
+++ b/Documentation/rust/testing.rst
@@ -123,6 +123,14 @@ A current limitation is that KUnit does not support assertions in other tasks.
 Thus, we presently simply print an error to the kernel log if an assertion
 actually failed. Additionally, doctests are not run for nonpublic functions.
 
+As these example tests might be used as examples for "real code" they should
+be written like "real code". For example, instead of using ``unwrap()``/``expect()``
+use the ``?``-operator. See:
+
+	https://rust.docs.kernel.org/kernel/error/type.Result.html#error-codes-in-c-and-rust
+
+for some background.
+
 The ``#[test]`` tests
 ---------------------
 
-- 
2.46.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-01-12 13:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-07  6:21 [PATCH] docs: rust: Add error handling sections Dirk Behme
2025-01-07  6:21 ` [PATCH] rust: error: Extend the Result documentation Dirk Behme
2025-01-07 12:16   ` Daniel Sedlak
2025-01-07 12:54   ` Alice Ryhl
2025-01-12 13:10   ` Miguel Ojeda
2025-01-12 13:45 ` [PATCH] docs: rust: Add error handling sections Miguel Ojeda

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox