1 // SPDX-License-Identifier: GPL-2.0 1 // SPDX-License-Identifier: GPL-2.0 2 2 3 //! Rust minimal sample. 3 //! Rust minimal sample. 4 4 5 use kernel::prelude::*; 5 use kernel::prelude::*; 6 6 7 module! { 7 module! { 8 type: RustMinimal, 8 type: RustMinimal, 9 name: "rust_minimal", 9 name: "rust_minimal", 10 author: "Rust for Linux Contributors", 10 author: "Rust for Linux Contributors", 11 description: "Rust minimal sample", 11 description: "Rust minimal sample", 12 license: "GPL", 12 license: "GPL", 13 } 13 } 14 14 15 struct RustMinimal { 15 struct RustMinimal { 16 numbers: Vec<i32>, 16 numbers: Vec<i32>, 17 } 17 } 18 18 19 impl kernel::Module for RustMinimal { 19 impl kernel::Module for RustMinimal { 20 fn init(_module: &'static ThisModule) -> R 20 fn init(_module: &'static ThisModule) -> Result<Self> { 21 pr_info!("Rust minimal sample (init)\n 21 pr_info!("Rust minimal sample (init)\n"); 22 pr_info!("Am I built-in? {}\n", !cfg!( 22 pr_info!("Am I built-in? {}\n", !cfg!(MODULE)); 23 23 24 let mut numbers = Vec::new(); 24 let mut numbers = Vec::new(); 25 numbers.push(72, GFP_KERNEL)?; 25 numbers.push(72, GFP_KERNEL)?; 26 numbers.push(108, GFP_KERNEL)?; 26 numbers.push(108, GFP_KERNEL)?; 27 numbers.push(200, GFP_KERNEL)?; 27 numbers.push(200, GFP_KERNEL)?; 28 28 29 Ok(RustMinimal { numbers }) 29 Ok(RustMinimal { numbers }) 30 } 30 } 31 } 31 } 32 32 33 impl Drop for RustMinimal { 33 impl Drop for RustMinimal { 34 fn drop(&mut self) { 34 fn drop(&mut self) { 35 pr_info!("My numbers are {:?}\n", self 35 pr_info!("My numbers are {:?}\n", self.numbers); 36 pr_info!("Rust minimal sample (exit)\n 36 pr_info!("Rust minimal sample (exit)\n"); 37 } 37 } 38 } 38 }
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.