Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1// SPDX-License-Identifier: GPL-2.0
2
3//! Rust minimal sample.
4
5use kernel::prelude::*;
6
7module! {
8 type: RustMinimal,
9 name: "rust_minimal",
10 authors: ["Rust for Linux Contributors"],
11 description: "Rust minimal sample",
12 license: "GPL",
13 params: {
14 test_parameter: i64 {
15 default: 1,
16 description: "This parameter has a default of 1",
17 },
18 },
19}
20
21struct RustMinimal {
22 numbers: KVec<i32>,
23}
24
25impl kernel::Module for RustMinimal {
26 fn init(_module: &'static ThisModule) -> Result<Self> {
27 pr_info!("Rust minimal sample (init)\n");
28 pr_info!("Am I built-in? {}\n", !cfg!(MODULE));
29 pr_info!(
30 "test_parameter: {}\n",
31 *module_parameters::test_parameter.value()
32 );
33
34 let mut numbers = KVec::new();
35 numbers.push(72, GFP_KERNEL)?;
36 numbers.push(108, GFP_KERNEL)?;
37 numbers.push(200, GFP_KERNEL)?;
38
39 Ok(RustMinimal { numbers })
40 }
41}
42
43impl Drop for RustMinimal {
44 fn drop(&mut self) {
45 pr_info!("My numbers are {:?}\n", self.numbers);
46 pr_info!("Rust minimal sample (exit)\n");
47 }
48}