diff options
| author | Benno Lossin <[email protected]> | 2025-03-08 11:04:18 +0000 |
|---|---|---|
| committer | Miguel Ojeda <[email protected]> | 2025-03-16 20:59:18 +0000 |
| commit | 84837cf6fa541150a3012ea233225a7ecfa8771a (patch) | |
| tree | 3b5f5d06d58b42cd86ad123937c1fbc59447ac60 /rust/pin-init/examples/error.rs | |
| parent | rust: pin-init: move proc-macro documentation into pin-init crate (diff) | |
| download | kernel-84837cf6fa541150a3012ea233225a7ecfa8771a.tar.gz kernel-84837cf6fa541150a3012ea233225a7ecfa8771a.zip | |
rust: pin-init: change examples to the user-space version
Replace the examples in the documentation by the ones from the
user-space version and introduce the standalone examples from the
user-space version such as the `CMutex<T>` type.
The `CMutex<T>` example from the pinned-init repository [1] is used in
several documentation examples in the user-space version instead of the
kernel `Mutex<T>` type (as it's not available). In order to split off
the pin-init crate, all examples need to be free of kernel-specific
types.
Link: https://github.com/rust-for-Linux/pinned-init [1]
Signed-off-by: Benno Lossin <[email protected]>
Reviewed-by: Fiona Behrens <[email protected]>
Tested-by: Andreas Hindborg <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Miguel Ojeda <[email protected]>
Diffstat (limited to 'rust/pin-init/examples/error.rs')
| -rw-r--r-- | rust/pin-init/examples/error.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/rust/pin-init/examples/error.rs b/rust/pin-init/examples/error.rs new file mode 100644 index 000000000000..e0cc258746ce --- /dev/null +++ b/rust/pin-init/examples/error.rs @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: Apache-2.0 OR MIT + +#![cfg_attr(feature = "alloc", feature(allocator_api))] + +use core::convert::Infallible; + +#[cfg(feature = "alloc")] +use std::alloc::AllocError; + +#[derive(Debug)] +pub struct Error; + +impl From<Infallible> for Error { + fn from(e: Infallible) -> Self { + match e {} + } +} + +#[cfg(feature = "alloc")] +impl From<AllocError> for Error { + fn from(_: AllocError) -> Self { + Self + } +} + +#[allow(dead_code)] +fn main() {} |
