rust_minimal.rs 856 B

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