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