Files

49 lines
1.1 KiB
Rust
Raw Permalink Normal View History

2021-07-03 17:21:12 +02:00
// SPDX-License-Identifier: GPL-2.0
//! Rust minimal sample.
use kernel::prelude::*;
module! {
type: RustMinimal,
name: "rust_minimal",
2025-03-09 14:57:11 -03:00
authors: ["Rust for Linux Contributors"],
description: "Rust minimal sample",
license: "GPL",
params: {
test_parameter: i64 {
default: 1,
description: "This parameter has a default of 1",
},
},
2021-07-03 17:21:12 +02:00
}
struct RustMinimal {
numbers: KVec<i32>,
2021-07-03 17:21:12 +02:00
}
impl kernel::Module for RustMinimal {
fn init(_module: &'static ThisModule) -> Result<Self> {
pr_info!("Rust minimal sample (init)\n");
pr_info!("Am I built-in? {}\n", !cfg!(MODULE));
pr_info!(
"test_parameter: {}\n",
*module_parameters::test_parameter.value()
);
2021-07-03 17:21:12 +02:00
let mut numbers = KVec::new();
numbers.push(72, GFP_KERNEL)?;
numbers.push(108, GFP_KERNEL)?;
numbers.push(200, GFP_KERNEL)?;
2021-07-03 17:21:12 +02:00
Ok(RustMinimal { numbers })
}
}
impl Drop for RustMinimal {
fn drop(&mut self) {
pr_info!("My numbers are {:?}\n", self.numbers);
pr_info!("Rust minimal sample (exit)\n");
}
}