Miguel Ojeda | e4fc658 | 2021-07-03 17:21:12 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | |
| 3 | //! Rust minimal sample. |
| 4 | |
| 5 | use kernel::prelude::*; |
| 6 | |
| 7 | module! { |
| 8 | type: RustMinimal, |
Gary Guo | b13c988 | 2022-11-10 17:41:19 +0100 | [diff] [blame] | 9 | name: "rust_minimal", |
| 10 | author: "Rust for Linux Contributors", |
| 11 | description: "Rust minimal sample", |
| 12 | license: "GPL", |
Miguel Ojeda | e4fc658 | 2021-07-03 17:21:12 +0200 | [diff] [blame] | 13 | } |
| 14 | |
| 15 | struct RustMinimal { |
| 16 | numbers: Vec<i32>, |
| 17 | } |
| 18 | |
| 19 | impl kernel::Module for RustMinimal { |
| 20 | fn init(_module: &'static ThisModule) -> Result<Self> { |
| 21 | pr_info!("Rust minimal sample (init)\n"); |
| 22 | pr_info!("Am I built-in? {}\n", !cfg!(MODULE)); |
| 23 | |
| 24 | let mut numbers = Vec::new(); |
Wedson Almeida Filho | 5ab560c | 2024-03-27 22:36:00 -0300 | [diff] [blame] | 25 | numbers.push(72, GFP_KERNEL)?; |
| 26 | numbers.push(108, GFP_KERNEL)?; |
| 27 | numbers.push(200, GFP_KERNEL)?; |
Miguel Ojeda | e4fc658 | 2021-07-03 17:21:12 +0200 | [diff] [blame] | 28 | |
| 29 | Ok(RustMinimal { numbers }) |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | impl Drop for RustMinimal { |
| 34 | fn drop(&mut self) { |
| 35 | pr_info!("My numbers are {:?}\n", self.numbers); |
| 36 | pr_info!("Rust minimal sample (exit)\n"); |
| 37 | } |
| 38 | } |