Skip to content

Commit 562cc3c

Browse files
dirkbehmeojeda
authored andcommitted
docs: rust: Add error handling sections
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. Suggested-by: Miguel Ojeda <[email protected]> Link: https://lore.kernel.org/rust-for-linux/CANiq72keOdXy0LFKk9SzYWwSjiD710v=hQO4xi+5E4xNALa6cA@mail.gmail.com/ Signed-off-by: Dirk Behme <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ Slightly tweaked wording. - Miguel ] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 52ae96f commit 562cc3c

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

Documentation/rust/coding-guidelines.rst

+8
Original file line numberDiff line numberDiff line change
@@ -373,3 +373,11 @@ triggered due to non-local changes (such as ``dead_code``).
373373
For more information about diagnostics in Rust, please see:
374374

375375
https://doc.rust-lang.org/stable/reference/attributes/diagnostics.html
376+
377+
Error handling
378+
--------------
379+
380+
For some background and guidelines about Rust for Linux specific error handling,
381+
please see:
382+
383+
https://rust.docs.kernel.org/kernel/error/type.Result.html#error-codes-in-c-and-rust

Documentation/rust/testing.rst

+7
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ A current limitation is that KUnit does not support assertions in other tasks.
123123
Thus, we presently simply print an error to the kernel log if an assertion
124124
actually failed. Additionally, doctests are not run for nonpublic functions.
125125

126+
Since these tests are examples, i.e. they are part of the documentation, they
127+
should generally be written like "real code". Thus, for example, instead of
128+
using ``unwrap()`` or ``expect()``, use the ``?`` operator. For more background,
129+
please see:
130+
131+
https://rust.docs.kernel.org/kernel/error/type.Result.html#error-codes-in-c-and-rust
132+
126133
The ``#[test]`` tests
127134
---------------------
128135

0 commit comments

Comments
 (0)